Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bottom sheet margin top not working correctly - Android

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

like image 315
Salmaan Avatar asked May 15 '17 05:05

Salmaan


People also ask

What does margin top does?

The margin-top CSS property sets the margin area on the top of an element. A positive value places it farther from its neighbors, while a negative value places it closer.

What is margin top Android?

android:layout_marginTopSpecifies extra space on the top side of this view. This space is outside this view's bounds. Margin values should be positive. May be a dimension value, which is a floating point number appended with a unit such as " 14.5sp ".

What is bottom sheet in Android?

Bottom Sheet dialogs seem to be replacing regular Android dialogs and menus. The Bottom Sheet is a component that slides up from the bottom of the screen to showcase additional content in your application. A Bottom Sheet dialog is like a message box triggered by the user's actions.


1 Answers

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"
like image 182
Valery M Avatar answered Oct 23 '22 03:10

Valery M