当复选框位于其一部分时,ImageView 停止可点击

ImageView stop being clicable when check box is on part of it

我创建了简单的 GridView Gallery。我展示一些照片。现在,我正在尝试为它们添加复选框。复选框在我的图像上可见,但现在单击操作不起作用(在 onItemClick 之前我缩放了图片)。所以我的想法是,如果我单击除了复选框位置以外的照片,它会缩放,但如果我单击复选框,它会 checked/unchecked.

我的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ImageView
        android:layout_width="@integer/width"
        android:layout_height="@integer/height"
        android:adjustViewBounds="true"
        android:id="@+id/imageView"
        android:layout_margin="5dp"
        android:layout_centerVertical="true"
        android:layout_alignParentEnd="true" />

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignRight="@+id/imageView" />


</RelativeLayout>

你可以试试这个

       <FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_centerVertical="true"
            android:layout_margin="5dp"
            android:adjustViewBounds="true"/>

        <CheckBox
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"/>

       </FrameLayout>

将这些属性添加到您的 xml CheckBox

 android:clickable="false"
 android:focusable="false"