Ems是什么意思(与TextView相关)?例如在
android:ems setEms(int)
使TextView恰好是这么多ems宽。
Ems是什么意思(与TextView相关)?例如在
android:ems setEms(int)
使TextView恰好是这么多ems宽。
当前回答
ems或setEms(n)设置TextView的宽度,以适应n 'M'字母的文本,而不管实际的文本扩展名和文本大小。参见wikipedia Em unit
但仅当layout_width设置为“wrap_content”时。其他layout_width值覆盖ems宽度设置。
添加一个android:textSize属性决定了视图的物理宽度为上面n 'M的文本的textSize *长度。
其他回答
单位是计量单位
名称em最初是对大写M的宽度的引用。它将TextView/EditText的宽度设置为适合n 'M'字母的文本,而不管实际的文本扩展名和文本大小。
Eg :
使EditText的宽度正好是这么多ems。
<EditText
android:ems="2"
/>
表示字母M宽度的两倍。
em基本上是CSS的字体大小属性。
The em and ex units depend on the font and may be different for each element in the document. The em is simply the font size. In an element with a 2in font, 1em thus means 2in. Expressing sizes, such as margins and paddings, in em means they are related to the font size, and if the user has a big font (e.g., on a big screen) or a small font (e.g., on a handheld device), the sizes will be in proportion. Declarations such as text-indent: 1.5em and margin: 1em are extremely common in CSS.
来源:https://www.w3.org/Style/Examples/007/units
Em是字体宽度的印刷单位。16号字体中的一个em就是16个点
ems或setEms(n)设置TextView的宽度,以适应n 'M'字母的文本,而不管实际的文本扩展名和文本大小。参见wikipedia Em unit
但仅当layout_width设置为“wrap_content”时。其他layout_width值覆盖ems宽度设置。
添加一个android:textSize属性决定了视图的物理宽度为上面n 'M的文本的textSize *长度。
它是在给定的英文字体大小下字母M的宽度。 所以2em是给定字体中字母M宽度的两倍。 对于非英文字体,它是该字体中最宽字母的宽度。这个宽度大小(以像素为单位)与英文字体中M的宽度大小不同,但仍然是1em。 所以如果我使用英文字体的12sp文本,1em相对于这个12sp英文字体;使用12sp的意大利字体得到的1em像素宽度与英文字体不同。