android ListView Item和CheckBox、Button点击事件冲突的问题
16lz
2021-01-23
在Item的根目录上设置属性:
//表示锁定子View的焦点,不让Layout下的子View获取android:descendantFocusability="blocksDescendants"
CheckBox和Button设置属性:
//三个属性都需要设置为falseandroid:focusable="false"android:focusableInTouchMode="false"android:clickable="false"
完整的布局文件示例:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:descendantFocusability="blocksDescendants" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="45dp" android:orientation="horizontal"> <CheckBox android:id="@+id/box" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:visibility="gone" android:focusable="false" android:focusableInTouchMode="false" android:clickable="false" android:layout_marginLeft="8dp" android:button="@drawable/check_box_background" android:gravity="center_vertical" /> <TextView android:id="@+id/text_name" android:layout_width="wrap_content" android:paddingRight="5dp" android:layout_weight="0.1" android:layout_height="match_parent" android:gravity="center_vertical" android:layout_marginLeft="20dp" android:text="点名" android:textColor="@color/gray2" android:textSize="14sp" /> <TextView android:id="@+id/text_workinfo" android:layout_width="0dp" android:layout_weight="0.99" android:layout_height="wrap_content" android:gravity="center_vertical" android:paddingLeft="5dp" android:minHeight="45dp" android:layout_marginRight="5dp" android:text="0.0" android:textColor="@color/green" android:textSize="14sp" /> <TextView android:id="@+id/text_edit" android:layout_width="0dp" android:layout_weight="0.4" android:paddingTop="8dp" android:paddingBottom="8dp" android:layout_height="wrap_content" android:gravity="center" android:layout_marginRight="5dp" android:text="编辑" android:textColor="@color/black" android:background="@drawable/border_line_corner_blue" android:textSize="14sp" /> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="1dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:visibility="visible" android:background="@color/gray" /></LinearLayout>
更多相关文章
- Android Intent实现页面跳转的方法示例
- Android布局属性介绍
- 简解selector的几个属性
- android一些有用的View属性
- ImageView androidscaleType属性详解
- android布局中的基本属性:
- Android 搜索框:SearchView 的属性和用法详解