i can make smaller last 2 number but i want them to show top as shown below picture.
TextView TV = (TextView)findViewById(R.id.txt);
Spannable WordtoSpan = new SpannableString("13.500,27");
WordtoSpan.setSpan( new TextAppearanceSpan(null, 0, 12, null, null), WordtoSpan.length()-2, WordtoSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TV.setText(WordtoSpan);
Thanks talha
Edit:
You can use SuperscriptSpan()
Spannable WordtoSpan = new SpannableString("13.500,27");
WordtoSpan.setSpan( new TextAppearanceSpan(null, 0, 17, null, null), WordtoSpan.length()-2, WordtoSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
WordtoSpan.setSpan( new SuperscriptSpan(), WordtoSpan.length()-2, WordtoSpan.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Increase font size to see the effect
Try this I don't find any other way, but to append the superscript text to original spannalbe string
Apply Spans what ever you want for the SpannableStringBuilder
SpannableStringBuilder builder=new SpannableStringBuilder("13.500,");
builder.append(Html.fromHtml("X<sup>27</sup>"))
Edit 2
If you create custom span like below, it align supertext to top absolutely. But if you use default SuperscriptSpan ,it couldnt make the text alignt to top.
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With