How the android:Ems attribute works (Textview)

Asked

Viewed 7,686 times

11

I would like to understand how this attribute works (android:ems).

I saw something citing that he acts on the source of the text, but I did not understand how. I tried to do some tests, and did not notice result.

Does anyone know how he acts about a TextView?

2 answers

8


The ems is used to define the width of the components with respect to the current source, thus its TextView will have the width needed to display the amount of characters you set using the ems.

In the meantime, it is necessary to define the layout_width as wrap_content, because the other layout types overwrite the width setting ems.

  • So that’s why, because mine layout_width is defined as 0, and layout_weight=1000, thus being a size proportional to the space reserved to it in relation to the other components Parent. So like you said it makes no sense to use the attribute ems, in my case. Right? Since it does not interfere with the font as I imagine, but rather with the width of the component to support a certain amount of characters. Still useful for other cases.

  • @Fernando exactly, changes the width of the component if the layout_width is defined as wrap_content

  • This property then would be very interesting to use in a EditText, that for example I want to have visible space for 15 characters.

7

ems is a unit of length defined in relation to the source used.
1em represents the length of the letter m.

When, for example, in a TextView the attribute is defined android:ems="15" you are limiting the length of Textview to 15 letters m.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.