ListView/GridView 的Item中的CheckBox點擊衝突的問題

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初始的時候沒有獲取焦點。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章