0

I have an array of Strings that I want to display within a proper format for my TextViews. I have already looked at using the Html.fromHtml() approach as posted here but I still can't figure out my specific solution.

The issue that I encounter is I am not sure how to format just a portion of the string. The "^" char should be a super script and the "_" underscore should be a subscript. Anything within brackets "{}" means that the superscript/subscript should apply to everything within it.

For example: The string ^2S_{1/2} should be displayed as: 2S1/2

Another example: 1s^2 should be formatted within a textview to appear as such: 1S2

I have been stumped for the past couple hours. All help is appreciated. Thank you!

4

1 回答 1

1

对于格式化此 ^2S_{1/2} 的示例,您将字符串值写为

“<sup><small>2</small></sup> S <sub><small>½</small></sub>”。

并在他们的代码中编写符号,并在您的 TextView setText() 方法中使用 Html.fromHtml() 。

于 2015-09-17T11:14:21.497 回答