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 I'm new with Android, so any help is appreciated. Thanks!
SpannableStringBuilder numSpan = new SpannableStringBuilder(String.valueOf(num));
SpannableStringBuilder denSpan = new SpannableStringBuilder(String.valueOf(den));
numSpan.setSpan(new SuperscriptSpan(), 0, numSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
denSpan.setSpan(new SubscriptSpan(), 0, denSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
outputText.setText(numSpan + "/" + denSpan, TextView.BufferType.SPANNABLE););
Try
Html.fromHtml
instead. Simple and precise:Note: You may need to give some height to the textview else the output will be clipped.
Alternatively, you could try this, where the number size is smaller: