根据字符设置 TextView 的宽度 [英] Set width of TextView in terms of characters

查看:17
本文介绍了根据字符设置 TextView 的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

真的在寻找答案到这个.

想要根据数字或字符设置 TextView 的宽度.因此,如果我希望它始终为 3 个字符宽,我可以设置它,它会根据 textSize 设置进行调整.没有这个,我必须将宽度设置为 50dip 或其他东西,这可能是正确的,也可能不是正确的,具体取决于字体大小.

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.

推荐答案

回答我自己的问题...

Answering my own question...

而获胜者是:设置minEms属性(android:minEms)!!!

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

所以ems"原来是指最宽的尺寸字符,通常是M",明白吗?因此,在 EditText 或 TextView 上将 minEms 设置为整数值(例如 3)应确保其宽度至少为 3 个字符.您也可以设置 maxEms.

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.

这篇关于根据字符设置 TextView 的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆