最近在写一个页面,使用了EditText,发现了一个有意思的问题。
这个页面使用了多个EditText的,EditText是这样设置的:
<RelativeLayout
android:id="@+id/newperson_idcard_layout"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="@+id/newperson_devider2"
android:layout_marginLeft="15dp"
android:background="@color/white">
<TextView
android:id="@+id/newperson_idcard_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="身份证:"
android:textColor="#8d8d8d"
android:textSize="14sp" />
<EditText
android:id="@+id/newperson_idcard"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/newperson_idcard_desc"
android:background="@null"
android:digits="0123456789xyzXYZ"
android:inputType="number"
android:maxLength="18"
android:singleLine="true"
android:imeOptions="actionNext"
android:textColor="#202020"
android:textSize="14sp"
android:focusableInTouchMode="true"
android:focusable="true"
android:nextFocusForward="@+id/newperson_hukou"/>
</RelativeLayout>
代码是这么处理的:
newperson_name = (EditText)findViewById(R.id.newperson_name);
newperson_idcard=(EditText)findViewById(R.id.newperson_idcard);
newperson_phone = (EditText)findViewById(R.id.newperson_phone);
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.newperson_name:
case R.id.newperson_idcard:
case R.id.newperson_phone:
view.setFocusable(true);
view.setFocusableInTouchMode(true);
view.requestFocus();
view.requestFocusFromTouch();
break;
但是按几个EditText,依然不响应。在一次偶然的测试发现,EditText获取了焦点,只是需要拼命按几下才有响应。于是想到EditText的响应区域可能是比较小。
于是只是将EditText的宽度从wrap_content改成match_parent,问题就解决了。
<RelativeLayout
android:id="@+id/newperson_idcard_layout"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_below="@+id/newperson_devider2"
android:layout_marginLeft="15dp"
android:background="@color/white">
<TextView
android:id="@+id/newperson_idcard_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="身份证:"
android:textColor="#8d8d8d"
android:textSize="14sp" />
<EditText
android:id="@+id/newperson_idcard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/newperson_idcard_desc"
android:background="@null"
android:digits="0123456789xyzXYZ"
android:inputType="number"
android:maxLength="18"
android:singleLine="true"
android:imeOptions="actionNext"
android:textColor="#202020"
android:textSize="14sp"
android:focusableInTouchMode="true"
android:focusable="true"
android:nextFocusForward="@+id/newperson_hukou"/>
</RelativeLayout>