1)SpannableString从原始文本创建一个
SpannableString string = new SpannableString(originalText)
Run Code Online (Sandbox Code Playgroud)
2)为符号设置a SuperscriptSpan和aRelativeSizeSpan$
string.setSpan(new SuperscriptSpan(), 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
string.setSpan(new RelativeSizeSpan((0.5f), 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
Run Code Online (Sandbox Code Playgroud)
3)单独保留整数部分.
4)获取小数部分的索引并对其应用a SuperscriptSpan和a RelativeSizeSpan.
string.setSpan(new SuperscriptSpan(), originalText.lenght - 2, originalText.lenght - 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
string.setSpan(new RelativeSizeSpan((0.5f), originalText.lenght - 2, originalText.lenght - 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
Run Code Online (Sandbox Code Playgroud)
5)适用SpannableString于TextView
textView.setText(string);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1004 次 |
| 最近记录: |