如何在android studio中编写一个分数。对于我试图生成水平线的分数的最佳实践是什么。
答案 0 :(得分:3)
使用html格式。但是,您必须在顶部和底部添加额外的空间,以防止它被切断。
SpannableStringBuilder test = new SpannableStringBuilder();
test.append("\n");
test.append(Html.fromHtml("<sup>5</sup>/<sub>9</sub>"));
test.append("\n");
答案 1 :(得分:2)
您可以尝试此解决方案:http://blog.sqisland.com/2014/11/android-stacked-fractions.html
基本上,您必须寻找支持afrc的字体。现在,您可以使用TextViews和TagHandler,直到获得所需的结果。
答案 2 :(得分:0)
解决方案似乎并不简单,但是如果你想在xml中尝试分数,请访问这个网站。
http://unicode-search.net/unicode-namesearch.pl?term=fraction
此代码对我来说是显示 1 / 4 。
xml代码是。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="\u00BC"
android:id="@+id/textView"
android:textSize="25sp" />
所需的行为android:text="\u00BC"
,以 1 / 4 显示为分数。
因此,如果您想显示 1 / 2 或其他任何来自上述网站的分数,只需附加最后两个字符(在这种情况下) BD
}至\u00
。
所以1/2变为\ u00BD