What is meant by Ems? (Android TextView)

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.


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.


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


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.


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


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