'Unable to close or drag BottomSheet/TopSheet when AppBarLayout pushes RecyclerView below the peek height

I am unable to close or drag the TopSheet/BottomSheet when the AppBarLayout is expanded. After analyzing it, I realized that it can be dragged if I pulled it from the tiny area shown in the screenshot. The dotted line just above the bottom refers to RecyclerView boundaries when the AppBarLayout is expanded, which might cause a non-draggable area, as shown in the screenshot below.

Screenshot: enter image description here

Code:

hero_library.xml

<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
    android:background="@drawable/rounded_music_bottom_sheet"
    tools:context=".ui.notifications.NotificationsFragment">

    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:id="@+id/main_parent"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:nestedScrollingEnabled="false"
        app:layout_constraintBottom_toTopOf="@+id/tabLayout"
        app:layout_constraintTop_toTopOf="parent">

        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:background="@color/green_500">

            <com.google.android.material.appbar.CollapsingToolbarLayout
                android:id="@+id/collapse_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:collapsedTitleTextAppearance="@style/TextAppearance.App.CollapsingToolbar.Collapsed"
                app:expandedTitleMargin="24dp"
                app:expandedTitleTextAppearance="@style/TextAppearance.App.CollapsingToolbar.Expanded"
                app:layout_scrollFlags="scroll|exitUntilCollapsed"
                app:toolbarId="@id/tool_bar">

                <com.google.android.material.appbar.MaterialToolbar
                    android:id="@+id/tool_bar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:elevation="0dp"
                    app:layout_collapseMode="pin"
                    app:navigationIcon="@drawable/ic_up_arrow"
                    app:navigationIconTint="@color/white"
                    app:title="Heroes" />
            </com.google.android.material.appbar.CollapsingToolbarLayout>
        </com.google.android.material.appbar.AppBarLayout>

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/list_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/white"
            android:clipToPadding="false"
            android:paddingTop="6dp"
            app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
            app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
            app:layout_constraintBottom_toTopOf="@+id/tabLayout"
            app:layout_constraintTop_toBottomOf="@+id/appBarLayout"
            tools:listitem="@layout/item_library" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>


    <com.google.android.material.tabs.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:background="@color/white_smoke"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/more_iv"
        app:layout_constraintStart_toEndOf="@+id/sleep_iv"
        app:tabIndicatorFullWidth="false"
        app:tabIndicatorGravity="top"
        app:tabSelectedTextColor="@color/black"
        app:tabTextColor="@color/dark_grey">

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Heroes" />

        <com.google.android.material.tabs.TabItem
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Favourite" />
    </com.google.android.material.tabs.TabLayout>


    <ProgressBar
        android:id="@+id/loading_pb"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <View
        android:id="@+id/holder"
        android:layout_width="30dp"
        android:layout_height="4dp"
        android:layout_marginBottom="8dp"
        android:background="@drawable/rounded_white"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/sleep_iv"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginStart="24dp"
        android:layout_marginTop="4dp"
        android:background="?selectableItemBackground"
        android:contentDescription="@string/app_name"
        android:onClick="onSleepClick"
        android:scaleType="centerInside"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/tabLayout"
        app:srcCompat="@drawable/ic_more_vertical" />


    <androidx.appcompat.widget.AppCompatImageView
        android:id="@+id/more_iv"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginTop="4dp"
        android:layout_marginEnd="24dp"
        android:background="?selectableItemBackground"
        android:scaleType="center"
        android:src="@drawable/ic_more_vertical"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="@+id/tabLayout" />
</androidx.constraintlayout.widget.ConstraintLayout>

hero_player.xml

<FrameLayout
    android:id="@+id/top_fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:behavior_peekHeight="56dp"
    app:layout_behavior=".utils.TopSheetBehavior"
    app:layout_constraintBottom_toTopOf="@id/nav_view"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <fragment
        android:id="@+id/nav_host_fragment_music"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/hero_navigation"
</FrameLayout>

For TopSheet I am using this: https://github.com/carlos-mg89/TopSheetBehavior



Solution 1:[1]

You need to change your layout heirachy root layout need to be coordinator layout, and wrap your recycler in constrain layout and give app behaviour to contstraion layout

<androidx.coordinatorlayout.widget.CoordinatorLayout>
      <com.google.android.material.appbar.AppBarLayout>
      </com.google.android.material.appbar.AppBarLayout>

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"
    >
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Islam Assem