将EditText宽度设置为精确的字符长度

时间:2014-01-25 12:28:55

标签: android user-interface android-edittext

我希望我的EditText输入正好x(x = 13)个符号(数字),我希望它从头开始准备这个宽度。我不希望它在打字或过度扩展时延长。必须修复它。 我看了another stackoverflow issue

并使用设置ems = 13的解决方案,但EditText仍然比13位数更宽(如2x)。如何解决我的问题?

    <EditText
        android:id="@+id/barcode_manual_edit"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:inputType="number"
        android:ems="13"
        android:maxLength="13"
        />

1 个答案:

答案 0 :(得分:1)

除了玩android:ems之类的内容之外,您还需要将android:typeface设置为monospace。否则,字符本身的宽度会有所不同,你无法实现“正好x(x = 13)个符号(数字)”。

相关问题