Ems是什么意思(与TextView相关)?例如在
android:ems setEms(int)
使TextView恰好是这么多ems宽。
Ems是什么意思(与TextView相关)?例如在
android:ems setEms(int)
使TextView恰好是这么多ems宽。
当前回答
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
其他回答
Ems是一个排版术语,它控制文本大小等。检查在这里
在Android中添加其他答案,Ems的大小,默认情况下,可以在每种语言和输入中有所不同。
这意味着如果您希望为文本字段设置最小宽度(由字符数定义),则必须根据Ems属性的字体和字体大小正确计算Ems并设置它。
对于那些在这方面有困难的人,你可以自己计算提示大小,以避免混淆Ems:
val tf = TextField()
val layout = TextInputLayout()
val hint = "Hint"
val measureText = tf.paint.measureText(hint).toInt()
tf.width = tf.paddingLeft + tf.paddingRight + measureText.toInt()
layout.hint = hint
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
它是在给定的英文字体大小下字母M的宽度。 所以2em是给定字体中字母M宽度的两倍。 对于非英文字体,它是该字体中最宽字母的宽度。这个宽度大小(以像素为单位)与英文字体中M的宽度大小不同,但仍然是1em。 所以如果我使用英文字体的12sp文本,1em相对于这个12sp英文字体;使用12sp的意大利字体得到的1em像素宽度与英文字体不同。
Em是字体宽度的印刷单位。16号字体中的一个em就是16个点