Set width of TextView in terms of characters

Fraggle picture Fraggle · May 28, 2011 · Viewed 37.1k times · Source

Really looking for an answer to this.

Want to set the width of a TextView based on a number or characters. So if I want it to always be 3 characters wide, I could set that and it will adjust based on the textSize setting. Without this, I have to set a width to 50dip or something, which may or may not be right depending on the font size.

Answer

Fraggle picture Fraggle · May 29, 2011

Answering my own question...

And the winner is: set the minEms attribute (android:minEms) !!!

So "ems" it turns out refers to the size of the widest character, typically an "M", get it? So setting minEms to an integer value say 3, on an EditText or TextView should ensure it's at least 3 characters wide. You can set the maxEms as well.

So Kyle's answer on this thread, although wrong, caused me to find the answer, so thanks Kyle.