GridView 中的 CheckBox 在 clickable=false 时仍然可以点击
CheckBox in GridView still clickable while clickable=false
我制作了一个带有适配器和项目布局的网格视图(在片段中)。布局存在一个 ImageView 来显示图片,一个 CheckBox 和另一个 ImageView 来显示一个指示器,指示图片是只是图片还是视频的缩略图。这是布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView
android:id="@+id/ivGridMedia"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:contentDescription="@string/imgObjectMediaDesc"/>
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/ivGridMedia"
android:layout_alignEnd="@+id/ivGridMedia"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false" />
<ImageView
android:id="@+id/vidIndicator"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:contentDescription="@string/imgPlayDesc"
android:visibility="gone"
android:src="@drawable/icon_play"/>
</RelativeLayout>
我正试图让这个 GridView 像画廊应用程序一样工作,所以(将来)CheckBox 在开始时是不可见的,但在长按该项目时,它将是可见的,用户将可以选择一些图片做点什么。
我不希望复选框可聚焦或可单击(我希望能够单击该项目以选中该复选框),但即使我已将复选框设置为不可聚焦或不可单击,我也可以仍然点击它,有人知道我该如何解决这个问题吗?
您可以设置 android:enabled="false"
以禁用 CheckBox
。
我制作了一个带有适配器和项目布局的网格视图(在片段中)。布局存在一个 ImageView 来显示图片,一个 CheckBox 和另一个 ImageView 来显示一个指示器,指示图片是只是图片还是视频的缩略图。这是布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<ImageView
android:id="@+id/ivGridMedia"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:contentDescription="@string/imgObjectMediaDesc"/>
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/ivGridMedia"
android:layout_alignEnd="@+id/ivGridMedia"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false" />
<ImageView
android:id="@+id/vidIndicator"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:contentDescription="@string/imgPlayDesc"
android:visibility="gone"
android:src="@drawable/icon_play"/>
</RelativeLayout>
我正试图让这个 GridView 像画廊应用程序一样工作,所以(将来)CheckBox 在开始时是不可见的,但在长按该项目时,它将是可见的,用户将可以选择一些图片做点什么。
我不希望复选框可聚焦或可单击(我希望能够单击该项目以选中该复选框),但即使我已将复选框设置为不可聚焦或不可单击,我也可以仍然点击它,有人知道我该如何解决这个问题吗?
您可以设置 android:enabled="false"
以禁用 CheckBox
。