gpt4 book ai didi

android 在 TextView 中显示分数

转载 作者:行者123 更新时间:2023-11-29 00:37:03 24 4
gpt4 key购买 nike

我似乎想不出一种在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com