Android TextView superscript

前端 未结 2 543
死守一世寂寞
死守一世寂寞 2021-01-07 07:21

So I\'m trying to add superscipt/subscript to a TextView, basically trying to make a fraction be displayed as 1/2. Not sure where I\'m going wrong, and

2条回答
  •  滥情空心
    2021-01-07 07:46

    You can use RelativeSizeSpan

    numSpan.setSpan(new SuperscriptSpan(), 0, numSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    numSpan.setSpan(new RelativeSizeSpan(0.5f), 0, numSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    

    or AbsoluteSizeSpan

    numSpan.setSpan(new SuperscriptSpan(), 0, numSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    numSpan.setSpan(new AbsoluteSizeSpan(28), 0, numSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    

提交回复
热议问题