Конфликт прослушивателя OnClick для элемента RecyclerView - PullRequest
0 голосов
/ 14 февраля 2020

Я реализую RecyclerView со списком элементов сетки, который выглядит как ниже. Изначально каждый элемент сетки НЕВИДИМ, и нажатие на его область делает его ВИДИМЫМ.

override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
    viewHolder.itemView.setOnClickListener {
        show()
    }
}

Кроме того, элемент сетки имеет КНОПКУ, и нажатие на нее направляет пользователя на другой экран. Однако прослушиватель кнопки onClick не срабатывает при нажатии на нее. Вместо этого вызывается прослушиватель onClick элемента viewView под держателем представления (т. Е. Будет отображаться красный элемент). Я думаю, что это связано с перекрытием области двух предметов. Тем не менее, дизайн должен быть сохранен и есть идеи, как решить эту проблему?

Ниже приведен макет, определенный для элемента просмотра

<androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ImageView
        android:id="@+id/main_image_view"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:visibility="invisible"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="ContentDescription"
        tools:visibility="visible" />

    <LinearLayout
        android:id="@+id/edit_button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp"       
        android:gravity="center"
        android:orientation="horizontal"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        android:visibility="invisible"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/main_image_view"
        tools:visibility="visible">

        <ImageView
            android:layout_width="18dp"
            android:layout_height="18dp"
            android:src="@drawable/btn_edit"
            tools:ignore="ContentDescription" />

        <TextView
            style="@style/edit_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="1dp"
            android:text="@string/edit_button" />

    </LinearLayout>

</androidx.constraintlayout.widget.ConstraintLayout>

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...