I have a question how I can make in TextView
diffrent font size something like this:
I found one way is maybe SpannableString
but I dont know is some better way?
I have a question how I can make in TextView
diffrent font size something like this:
I found one way is maybe SpannableString
but I dont know is some better way?
You can use the SpannableString
and SpannableStringBuilder
.
SpannableStringBuilder ssb = new SpannableStringBuilder("25 415,50 XX");
var realtiveSizeSpan = new RelativeSizeSpan(1.5f);
ssb.SetSpan(realtiveSizeSpan, 0, 6, 0);
textView.TextFormatted = ssb;
This sets a "formatting" for a given character range in the content. The SetSpan
sets a formatting of a substring, here I set it from index 0, for 6 characters. Note that you need to assigne the value to the TextFormatted
property instead of Text
.
The alternative would be to have two differently formatted TextView
controls next to each other (wrapped in a Horizontal
LinearLayout
for example), but such solution is less reliable and does not ensure that the texts will lay exactly in one straight line.