所以我找到了這個問題的答案張貼在這裏幫助下一個人。
我創建了一個輔助類包含的方法,調整跨度,您可以使用此語法調用它(這是設置的最後2個字符出現就行了更高):
SpannableString contentAmount = new SpannableString(amount);
contentAmount.setSpan(new SuperscriptSpanAdjuster(3.0/5.0), contentAmount.length() - 2, contentAmount.length(), SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
和輔助類是:
/**
* This is a helper class to help adjust the alignment of a section of text, when using SpannableStrings to set text
* formatting dynamically.
*
*/
import android.text.TextPaint;
import android.text.style.MetricAffectingSpan;
public class SuperscriptSpanAdjuster extends MetricAffectingSpan {
double ratio = 0.5;
public SuperscriptSpanAdjuster() {
}
public SuperscriptSpanAdjuster(double ratio) {
this.ratio = ratio;
}
@Override
public void updateDrawState(TextPaint paint) {
paint.baselineShift += (int) (paint.ascent() * ratio);
}
@Override
public void updateMeasureState(TextPaint paint) {
paint.baselineShift += (int) (paint.ascent() * ratio);
}
}
+1張貼的答案,幫助社區 – Guillaume
感謝分享 – Rotemmiz
還是剪輯過一個數字或文字的頂部 – JPM