EditText无法快速响应点击事件

最近在写一个页面,使用了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>



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值