Search code examples
android-layoutandroid-coordinatorlayoutandroid-design-librarybottom-sheet

Persistent bottom sheet peek covering last RecyclerView item


I have implemented a persistent bottom sheet in my layout - one that cannot be completely hidden but always peeks from the bottom. But it covers the last RecyclerView item. How can I set the layout in such a way the peek doesn't hide the last item?

Screenshot:-

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.widget.NestedScrollView
            android:id="@+id/nestedScrollView"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recylerView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_centerHorizontal="true"
                    android:layout_weight="1" />
            </RelativeLayout>
        </android.support.v4.widget.NestedScrollView>

        <!-- Buttom Sheet -->
        <android.support.v7.widget.LinearLayoutCompat
            android:id="@+id/bottom_sheet"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/white"
            android:orientation="vertical"
            app:behavior_hideable="true"
            app:behavior_peekHeight="56dp"
            app:layout_behavior="android.support.design.widget.BottomSheetBehavior">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="56dp"
                android:layout_gravity="center_vertical"
                android:background="@android:color/holo_green_dark"
                android:orientation="horizontal"
                android:padding="10dp"
                android:weightSum="3">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="10dp"
                    android:layout_weight="2"
                    android:text="Submit Report"/>

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:text="8/10"/>
            </LinearLayout>
            <!-- Other things to add -->
        </android.support.v7.widget.LinearLayoutCompat>

    </android.support.design.widget.CoordinatorLayout>
</FrameLayout>

Solution

  • This is silly. I knew the solution by myself right after posting the problem. :) Just needed to add android:paddingBottom attribute to the RecyclerView.

    <android.support.v7.widget.RecyclerView
                        android:id="@+id/studentListView"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:paddingBottom="56dp"/>