I've come across the elegantTextHeight attribute for a TextView but don't see any changes when I play with it.
What does it do? And how do I use it?
If you want to show a strike-through text you can do it programming using PaintFlags. You can set paint flags Paint. STRIKE_THRU_TEXT_FLAG to a TextView and it will add a strike-through to the text. TextView textView = (TextView) findViewById(R.
Inside the onClick(View v) implementation add: v. getId(); To determine whice TextView pressed.
The difference is that android:lineSpacingExtra add extra spacing between lines of text of TextView and android:lineSpacingMultiplier work as scale factor for height of line space. in other words, each line height will be height*multiplier + extra. Follow this answer to receive notifications.
Short answer: It's a method to turn off the "font compacting" optimization for some languages. And if you don't know what I'm saying, it's probably because your language doesn't have the "font compacting" optimization, which means you don't have to care about it.
Long answer:
Take a look at the doc first:
Set the paint's elegant height metrics flag. This setting selects font variants that have not been compacted to fit Latin-based vertical metrics, and also increases top and bottom bounds to provide more space.
What does it mean?
In some languages, some glyphs could be very tall. Like this:
(Those are characters I randomly picked from Thai Alphabet, if you're curious.)
Look at the texts on the left. Really tall, huh? But the fact is, it's not tall enough. It should've been taller.
Fonts usually have 2 variants for "tall text" languages: an original variant, and a compacted variant. The compacted version is to ensure texts won't look weird when texts of different languages are laid together. The default version (at least in Android's Paint
) is the compacted version, as shown in the screenshot above.
But sometimes you may need the original variant. If you need it, add this line:
paint.setElegantTextHeight(true);
Then your texts will be drawn with the original (elegant) variant.
The Thai texts become taller, see?
So, things are clear now: Some languages could have very tall glyphs, and they're compacted by default. And setElegantTextHeight(true)
will:
From the docs:
Set the paint's elegant height metrics flag. This setting selects font variants that have not been compacted to fit Latin-based vertical metrics, and also increases top and bottom bounds to provide more space.
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