15

I am working with bottom sheet and it is working great if I dont add margin top.

I want the bottom sheet to fill the screen when pulled up but it also goes behind the Action Bar.
To solve this, I added margin top to the bottom sheet equivalent to the height of action bar, it works great until bottom bar is back to bottom.

<RelativeLayout
    android:id="@+id/rl_bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="280dp"
    android:margin_top="60dp"
    app:behavior_peekHeight="80dp"
    app:behavior_hideable="false"
    app:layout_behavior="@string/bottom_sheet_behavior"
    android:background="@drawable/ic_camera">

When bottom sheet is slided down, margin is no more there and view above the screen becomes equal to peekHeight + marginTop

Before Expanded

How should I fix it?

Collapsed after expanding once

enter image description here

Cameron Ketcham
  • 7,966
  • 2
  • 28
  • 27
Salmaan
  • 3,543
  • 8
  • 33
  • 59

2 Answers2

2

One option is to use a Toolbar instead of adding a margin to the BottomSheet. You can put this inside the CoordinatorLayout at the top so it will be behind the BottomSheet. Make sure the View that has the BottomSheetBehavior is at the bottom of the layout and that it has a higher elevation than the Toolbar.

Cameron Ketcham
  • 7,966
  • 2
  • 28
  • 27
  • like that, the bottomSheet will go over toolbar, and the requirement is to be under the toolbar – ghita Jul 15 '19 at 11:18
2

I can suggest you to change the root layout - from CoordinatorLayout to any other (Relative/Linear and so on). And after that you can add your CoordinatorLayout in your new root ViewGroup with desired marginTop.

android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="80dp"
Valery M
  • 89
  • 3