如何EDITTEXT宽度设置为一个字符 [英] How to set editText width to one character
本文介绍了如何EDITTEXT宽度设置为一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开发一个Android应用程序,现在我正在建立,这将有四个EDITTEXT持有四位数密码的屏幕。
I'm developing an Android application and now I'm creating a password screen which will have four editText to hold four digits.
这是我的 password.xml
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/firstNum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="14dp"
android:layout_marginTop="191dp"
android:ems="10"
android:inputType="textPassword"
android:lines="1"
android:maxLength="1"
android:maxLines="1"
android:minLines="1" >
<requestFocus />
</EditText>
</RelativeLayout>
这是我所得到的:
And this is what I get:
但EDITTEXT太大。
But the editText is too big.
我怎样才能改变它的宽度为它适合仅一个字符?
推荐答案
如果你想设置你的身体的EditText的物理宽度可以使用
If you want to set physical your edittext's physical width you can use
android:maxWidth="your size in dp"
但如果你想在它接收单个字符,您可以使用
but if you want to receive single character in it you can use
android:maxLength="1"
这篇关于如何EDITTEXT宽度设置为一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文