我似乎无法找到一种方法来轻松地在 TextView 中显示分数。让我们更清楚地说,我需要在 TextView 中包含一个数字超过一个数字的分数,然后应该能够在同一个 TextView 中添加更多文本。我看过这个链接Android - displaying fractions using unicode
该解决方案效果不佳,尤其是在将其播放到警报对话框中时,格式会丢失。
这个我也试过
SpannableStringBuilder test = new SpannableStringBuilder();
SpannableString content = new SpannableString("3");
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
test.append(content);
test.append("\n");
test.append("56");
这非常有用,但是如果我需要向该行添加更多内容,它将显示在底部,而我需要它在顶行。如果我尝试插入顶行,那么底行将会移动,因为 TextView 居中(而且它也无法通过以任何特定方式对齐 TextView 来工作,因为我可能在分数之前有文本).. *我不想要多个 TextView
最佳答案
解决方案是使用链接中的 html 格式。但是,您必须在顶部和底部添加额外的空间,以防止其被切断。
SpannableStringBuilder test = new SpannableStringBuilder();
test.append("\n");
test.append(Html.fromHtml("<sup>5</sup>/<sub>9</sub>"));
test.append("\n");
关于android 在 TextView 中显示分数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11960859/