Android TextView 优雅TextHeight 有什么作用?(API 21) [英] Android TextView What does elegantTextHeight do? (API 21)

查看:28
本文介绍了Android TextView 优雅TextHeight 有什么作用?(API 21)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 TextView 的优雅文本高度属性,但在使用它时没有看到任何变化.

它有什么作用?我该如何使用它?

解决方案

简短回答:这是一种针对某些语言关闭字体压缩"优化的方法.如果你不知道我在说什么,那可能是因为你的语言没有字体压缩"优化,这意味着你不必关心它.

长答案:

先看一下文档:

<块引用>

设置油漆优雅的高度度量标志.此设置会选择尚未压缩的字体变体以适应基于拉丁语的垂直度量,并且还会增加顶部和底部边界以提供更多空间.

这是什么意思?

在某些语言中,某些字形可能非常高.像这样:

(这些是我从

泰文变得更高了,看到了吗?

所以,现在事情很清楚了:某些语言可能具有非常高的字形,并且默认情况下它们会被压缩.而 setElegantTextHeight(true) 将:

  1. 切换到原始的、非压缩的、优雅的变体来绘制文本.
  2. 增加上下边界以为较高的文本提供更多空间.

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?

解决方案

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:

  1. Switch to the original, non-compacted, elegant variant to draw texts.
  2. Increase the top and bottom bounds to provide more space for the taller texts.

这篇关于Android TextView 优雅TextHeight 有什么作用?(API 21)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆