您好,欢迎来到尔游网。
搜索
您的当前位置:首页关于RelativeLayout、LinearLayout添加点击事件失灵的问题

关于RelativeLayout、LinearLayout添加点击事件失灵的问题

来源:尔游网

       最近项目将近尾声,昨天测试来告诉我,这个按钮怎么不太灵活。

 刚开始我还开玩笑说,对android手机宽容一些。今天早上为了证明,确实是android系统的问题,我打log测试,于是发现了一个意外的事情。

界面如下:

 

要点击的是切换房源这里,为了增大点击面积:布局如下

<RelativeLayout
    android:id="@+id/switch_house"
    android:layout_width="100dp"
    android:layout_height="40dp"
    android:gravity="center_vertical"
   
   >
<ImageButton
    android:layout_alignParentRight="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@mipmap/switch_house" />
</RelativeLayout>
但是我发现,点击的时候有时候起作用,有时候不起作用,log显示的结果是有时候点击的时候,压根就没有走点击的方法。上网查了一下,有人说,外面包裹的点击事件 RelativeLayout布局的点击焦点有时候会被里面的ImageButton抢占,于是,有时候点击就失灵了。

我试着将里面的ImageBtton换成ImageVIew。给外面的RelativeLayout+“属性 focusableTouchMode ,然后运行,果然好使了。哈哈

修改后的布局:

<RelativeLayout
    android:id="@+id/switch_house"
    android:layout_width="100dp"
    android:layout_height="40dp"
    android:gravity="center_vertical"
    android:focusableInTouchMode="true"
   >
<ImageView
    android:layout_alignParentRight="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@mipmap/switch_house" />
</RelativeLayout>

一个小小的意外发现,希望给遇到类似问题的同学一些帮助!



因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- axer.cn 版权所有 湘ICP备2023022495号-12

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务