What is meant by Ems? (Android TextView)

前端 未结 7 1196
情歌与酒
情歌与酒 2020-11-29 15:27

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.<

相关标签:
7条回答
  • 2020-11-29 16:09

    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.

    0 讨论(0)
  • 2020-11-29 16:11

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

    0 讨论(0)
  • 2020-11-29 16:17

    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

    0 讨论(0)
  • 2020-11-29 16:18

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

    0 讨论(0)
  • 2020-11-29 16:23

    While other answers already fulfilled the question (it's a 3 years old question after all), I'm just gonna add some info, and probably fixed a bit of misunderstanding.

    Em, while originally meant as the term for a single 'M' character's width in typography, in digital medium it was shifted to a unit relative to the point size of the typeface (font-size or textSize), in other words it's uses the height of the text, not the width of a single 'M'.

    In Android, that means when you specify the ems of a TextView, it uses the said TextView's textSize as the base, excluding the added padding for accents/diacritics. When you set a 16sp TextView's ems to 4, it means its width will be 64sp wide, thus explained @stefan 's comment about why a 10 ems wide EditText is able to fit 17 'M'.

    0 讨论(0)
  • 2020-11-29 16:24

    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.

    0 讨论(0)
提交回复
热议问题