今天看啥  ›  专栏  ›  梦想之家xiao_chen

ListView/GridView 的Item中的CheckBox点击冲突的问题

梦想之家xiao_chen  · CSDN  ·  · 2020-01-04 12:20

1.自定义样式+扩大点击区域CheckBox

<CheckBox
  
    android:id="@+id/cb_select_item"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:button="@null"
    android:drawableLeft="@drawable/checkbox_button_iamge"
    android:drawableStart="@drawable/checkbox_button_iamge"
    android:padding="@dimen/common_measure_30dp"
    android:focusable="false"
    android:focusableInTouchMode="false"
    android:clickable="false"
    />

2.checkbox_button_iamge 文件是选择器

<?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@mipmap/sel_image2" android:state_checked="true"  />
        <item android:drawable="@mipmap/sel_image2" android:state_selected="true" />
        <item android:drawable="@mipmap/sel_image2" android:state_pressed="true" />
        <item android:drawable="@mipmap/unsel_image2" android:state_checked="false" />
</selector>

由于CheckBox的点击事件优先级比ListView/GridView 的高,所以要在checkbox中添加 android:focusable="false" android:focusableInTouchMode="false" android:clickable="false" ,使得CheckBox初始的时候没有获取焦点。




原文地址:访问原文地址
快照地址: 访问文章快照