我可以制作较小的最后2个数字,但我希望它们显示如下图所示的顶部.
TextView TV = (TextView)findViewById(R.id.txt);
Spannable WordtoSpan = new SpannableString("13.500,27");
WordtoSpan.setSpan( new TextAppearanceSpan(null,12,null,null),WordtoSpan.length()-2,WordtoSpan.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TV.setText(WordtoSpan);
谢谢塔哈
最佳答案
编辑:
原文链接:https://www.f2er.com/android/430864.html你可以使用SuperscriptSpan()
Spannable WordtoSpan = new SpannableString("13.500,27");
WordtoSpan.setSpan( new TextAppearanceSpan(null,17,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
WordtoSpan.setSpan( new SuperscriptSpan(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
试试这个
我没有找到任何其他方法,但将上标文本附加到原始spannalbe字符串
应用跨越SpannableStringBuilder所需的任何内容
SpannableStringBuilder builder=new SpannableStringBuilder("13.500,");
builder.append(Html.fromHtml("X
编辑2
如果您创建如下所示的自定义范围,则绝对将supertext与top对齐.但是如果你使用默认的SuperscriptSpan,它就无法使文本成为顶级.
public class SuperscriptSpan2 extends MetricAffectingSpan implements
ParcelableSpan {
public SuperscriptSpan2() {
}
public int getSpanTypeId() {
return TextUtils.CAP_MODE_CHARACTERS;
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel dest,int flags) {
}
@Override
public void updateDrawState(TextPaint tp) {
tp.baselineShift += (int) (tp.ascent() / 1.25);
}
@Override
public void updateMeasureState(TextPaint tp) {
tp.baselineShift += (int) (tp.ascent() / 1.25);
}
}