What is meant by Ems? (Android TextView)

2019-01-10 00:06发布

What is meant by Ems (related to a TextView)? For example in

android:ems     setEms(int)

Makes the TextView be exactly this many ems wide.

6条回答
对你真心纯属浪费
2楼-- · 2019-01-10 00:40

Ems is a typography term, it controls text size, etc. Check here

查看更多
聊天终结者
3楼-- · 2019-01-10 00:47

It is the width of the letter M in a given English font size.
So 2em is twice the width of the letter M in this given font.
For a non-English font, it is the width of the widest letter in that font. This width size in pixels is different than the width size of the M in the English font but it is still 1em.
So if I use a text with 12sp in an English font, 1em is relative to this 12sp English font; using an Italian font with 12sp gives 1em that is different in pixels width than the English one.

查看更多
劳资没心,怎么记你
4楼-- · 2019-01-10 00:54

ems is a unit of measurement

The name em was originally a reference to the width of the capital M. It sets the width of a TextView/EditText to fit a text of n 'M' letters regardless of the actual text extension and text size.

Eg :

android:ems Makes the EditText be exactly this many ems wide.

<EditText
    android:ems="2"
/>

denotes twice the width of letter M is created.

查看更多
劳资没心,怎么记你
5楼-- · 2019-01-10 01:01

em is the typography unit of font width. one em in a 16-point typeface is 16 points

查看更多
够拽才男人
6楼-- · 2019-01-10 01:04

em is basically CSS property for font sizes.

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.

Source:https://www.w3.org/Style/Examples/007/units

查看更多
啃猪蹄的小仙女
7楼-- · 2019-01-10 01:06

android:ems or setEms(n) sets the width of a TextView to fit a text of n 'M' letters regardless of the actual text extension and text size. See wikipedia Em unit

but only when the layout_width is set to "wrap_content". Other layout_width values override the ems width setting.

Adding an android:textSize attribute determines the physical width of the view to the textSize * length of a text of n 'M's set above.

查看更多
登录 后发表回答