Adjust recycler view height when persistent bottom sheet is expanded
I have a persistent bottom sheet (which is basically a button) and a recycler view both contained in a CoordinatorLayout.
When the bottom sheet is expanded, I do not want it to obscure the recycler view. I am able to achieve this by setting
app:layout_insetEdge="bottom" in the bottom sheet and
app:layout_dodgeInsetEdges="bottom" in the recycler view respectively.
However, since the recycler view's height is set to
android:layout_height="match_parent", its top partly moves out of the screen when the bottom sheet is expanded.
Instead, I want the recycler view to adjust its height dynamically occording to the height of the bottom sheet so it does not move out of the screen anymore. How can I achieve that?
Here is the complete layout:
<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="match_parent" android:nestedScrollingEnabled="false" app:layout_dodgeInsetEdges="bottom" /> <Button android:id="@+id/bottom_sheet" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/update_all" android:foreground="?attr/selectableItemBackground" android:background="@drawable/angled_button" app:behavior_hideable="false" app:behavior_peekHeight="0dp" app:layout_insetEdge="bottom" app:layout_behavior="android.support.design.widget.BottomSheetBehavior" /> </android.support.design.widget.CoordinatorLayout>
Edit: Screenshots added
Without the bottom sheet everything looks fine.
With the bottom sheet expanded the recycler view is not completely visible anymore.
Edit 2: GIF added
Android: Persistent bottom sheet peek covering last RecyclerView item, Faced the same issue recently, didn't find a better way than to remove app:layout_dodgeInsetEdges="bottom" and use padding instead. This is how it can be There are two types of bottom sheets, Persistent Bottom Sheet and Modal Bottom Sheet. > Persistent Bottom Sheet: The Persistent bottom sheet displays in-app content. It will be displayed at the bottom of the screen making some portion of the content visible. When activated it opens the full content. The elevation of the persistent bottom sheet is same as app making it part of the app. Below is the example of persistent bottom sheet of Google Maps app.
Android Bottom Sheet / Bottom Sheet Behavior, I have a persistent bottom sheet (which is basically a button) and a recycler view both contained in a CoordinatorLayout. When the bottom sheet is expanded, STATE_COLLAPSED: Sets the bottom sheet height with the value set on the peekHeight attribute. STATE_DRAGGING: The bottom sheet is being dragged; STATE_EXPANDED: The bottom sheet is completely expanded; STATE_HIDDEN: The bottom sheet is completely hidden from the screen; Let’s jump onto the business end of this tutorial.
Try putting this attribute to the RecyclerView:
Making most out of Android Bottom Sheet - Mihir Patel, I have a persistent bottom sheet (which is basically a button) and a recycler view both contained in a CoordinatorLayout. When the bottom In this tutorial we will learn, how to create a persistent bottom sheet, which we can drag up and down to show and hide its content. For the sheet we will use a NestedScrollView and set it’s layout_behavior to “BottomSheetBehavior” to tell the system that we want to use this NestedScrollView as our bottom sheet.
You can do 2 solutions
1 is to set top-margin to
Because your CoordinatorLayout is not aligning
Toolbar. So set top margin
2 If you want
RecyclerView comes up of
4dp elevation, and above 21 version layouts are layered by elevation. So set
<android.support.v7.widget.RecyclerView ... android:elevation="@dimen/design_appbar_elevation"/>
design_appbar_elevation value is
Handling Scrolls with CoordinatorLayout · codepath/android_guides , I have implemented a persistent bottom sheet in my layout - one that 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. RecyclerView android:paddingBottom="?dp" android:clipToPadding="false" /> replace "?dp" with the height of your Android Bottom Sheet is a component that slides up from the bottom of the screen having multiple options. Here are the examples of the Bottom sheet from apps. After creating a new project, open…
Material Design / Bottom Sheets in Design Support Library , It has a littler height. Persistent Bottom Sheet. Modal Bottom Sheet: This botom sheet Let’s add the first persistent bottom sheet to the layout. Designing the bottom sheet. A persistent bottom sheet is a part of the Activity view heirarchy.
Android Bottom Sheet Material Design with Example, Persistent bottom sheets: It can be implemented using BottomSheetBehavior in if you are using scrollview, dynamic views OR recyclerview in your fragment and contents When you don't have enough content to fit into EXPANDED state of a Which means, you can calculate the height of contents and set peekHeight of If you are trying to adjust the peek height, I found I had to extend and override bottom sheet. In the below case, I get the height of my view set in the sheet, or use the maximum height.
Any scroll events to the RecyclerView should trigger changes to the Only when scrolling reaches to the top will the view expand to its full height: Now, we need to set the title on the CollapsingToolBarLayout instead of the Toolbar. Persistent bottom sheets show in-app content, while modal sheets Bottom Sheet is the new material design widget and it is a simple bottom window display in the bottom of the screen. There have two type of Bottom Sheet which are Persistent and Modal. The first type Persistent Bottom Sheet is structural part of a User Interface and it is permanent in the activity, user can expand and collapse the view.