在Android中,如何创建固定宽度的EditText? [英] In Android, how to create EditText of fixed width?
问题描述
我想创建一个EditText只节选数字,最多有4个数字,并且永远不会窄于仿佛充满了4号这将是(不空当缩小,或有扩大,以容纳4号......是固定的。)
I would like to create an EditText which only excepts numbers, has a maximum of 4 numbers, and is never narrower than it would be if filled with 4 numbers (does not shrink when empty, or have to expand to accommodate 4 numbers... is fixed.)
第2完成用:机器人:inputType =数字和android:最大长度=4。如何设置的最小长度?
The first 2 are accomplished with: android:inputType="number" and android:maxLength="4". How can I set the minimum length?
感谢你。
推荐答案
小的hackish ,但你可以把你的的EditText
在< $ C C>的FrameLayout $旁边另一个的TextView
与文本=0000
和的知名度=不可见的。
的FrameLayout
应该有宽度= WRAP_CONTENT
和您的的EditText
将宽度= FILL_PARENT
。照片,应该使之正确的宽度总是这样。
A little hackish, but you can put your EditText
inside a FrameLayout
alongside with another TextView
with text="0000"
and visibility=invisible.
FrameLayout
Should have width=wrap_content
and your EditText
will have width=fill_parent
.
That should make it the right width always.
这样做的好处是,它是100%的XML端,没有code参与。
The advantage of this is, it's 100% xml-side, no code involved.
这篇关于在Android中,如何创建固定宽度的EditText?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!