Search code examples
androidandroid-linearlayout

Parent view height as match_parent but accepting click from views under (previous screen)


I am having a weird issue which might be very simple to solve but I don't know why its behaving like it does. I have two screens A and B. Navigation is from A -> B. On B, I have parent view as LinearLayout (LL) as

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    android:id="@+id/container"
    android:orientation="vertical"
    android:background="@color/tcRaspberry"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:animateLayoutChanges="true"
    android:layout_height="match_parent">

<include
        app:layout_constraintBottom_toTopOf="@+id/bottomSheetContainer"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:id="@+id/toolbarx"
        layout="@layout/include_toolbarx"/>

<androidx.constraintlayout.widget.ConstraintLayout
        android:layout_marginStart="@dimen/itinerary_start_margin"
        android:layout_marginEnd="@dimen/itinerary_start_margin"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    <androidx.appcompat.widget.AppCompatImageView
            android:contentDescription="@null"
            app:layout_constraintTop_toTopOf="parent"
            android:layout_marginTop="@dimen/itinerary_start_margin"
            app:layout_constraintStart_toStartOf="parent"
            android:id="@+id/myAccountImage"
            android:layout_gravity="center"
            app:srcCompat="@drawable/ic_panorama_circle_24dp"
            android:layout_width="@dimen/image_size_profile"
            android:layout_height="@dimen/image_size_profile"/>

    <androidx.appcompat.widget.AppCompatTextView
            android:textSize="20sp"
            android:contentDescription="@string/travel_counsellor_contact"
            android:layout_marginStart="@dimen/top_margin"
            app:layout_constraintTop_toTopOf="@+id/myAccountImage"
            app:layout_constraintStart_toEndOf="@+id/myAccountImage"
            app:layout_constraintBottom_toBottomOf="@+id/myAccountImage"
            android:id="@+id/myAccountTitle"
            android:textAppearance="@style/TcTextAppearance.Bold.Header"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/my_account"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>

Even though the parent LL's height (id: container) is set as match_parent and is filling whole screen, its still accepting click events from previous screen A. The only way I got it to not accept clicks from A is to put a ClickListener on it which seems like a hack to me. What can I do to prevent it taking clicks from A.


Solution

  • Make the view that should block the call clickable via xml android:clickable="true" or set a click handler for it from fragment/activity