答案 0 :(得分:1)
尝试以下方式在textview中实现上标
((TextView)findViewById(R.id.text)).setText(Html.fromHtml("<sup>10260</sup>"));
答案 1 :(得分:0)
<强>更新强> 尝试使用Spannable String:
SpannableString styledString = new SpannableString("10260");
// superscript
styledString.setSpan(new SuperscriptSpan(), 3, 5, 0);
// Give the styled string to a TextView
TextView textView = (TextView) findViewById(R.id.text);
textView.setText(styledString);
答案 2 :(得分:-1)
这个问题暂时搁置这里是我的解决方案,我通过在约束布局中使用两个不同大小的TextView来解决这个问题。没有其他解决方案适合我。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-15dp">
<TextView
android:id="@+id/balance_amount_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="107"
android:textSize="94sp"
app:layout_constraintStart_toEndOf="@+id/dollar_tv"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/balance_superscript_amount_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="2.5dp"
android:layout_toRightOf="@+id/balance_amount_tv"
android:text="50"
android:textSize="60sp"
app:layout_constraintBottom_toBottomOf="@+id/balance_amount_tv"
app:layout_constraintStart_toEndOf="@+id/balance_amount_tv"
app:layout_constraintTop_toTopOf="@+id/balance_amount_tv"
app:layout_constraintVertical_bias="0.3" />
</android.support.constraint.ConstraintLayout>