Android layout layout limit

How to set the edge to the bottom sheet in a fragment?

I have a linear layout at the bottom of the fragment, and now I want to expand the bottom sheet on top of this linear layout

android:layout_marginBottom="36dp" doesn't work and the bottom sheet covers the linear layout.

here is my code:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="36dp"
    android:background="@drawable/shadow"
    android:layout_gravity="bottom">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_add_white_24dp" />
</LinearLayout>

<LinearLayout
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ff0000"
    app:behavior_hideable="true"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
    android:layout_marginBottom="36dp">

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Test" />

</LinearLayout>
+4
source share
2 answers

I had the same problem that I had a little hack, but I made it work like that.

Essentially, a transparent linear layout with a bottom sheet is simply made, and then we place the view in it. Then a transparent lower bottom bottom is given.

<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:fitsSystemWindows="true"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="20dp"
>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:gravity="center"
    >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:transitionName="vatom"
        />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
    android:elevation="300dp"
    android:paddingBottom="20dp"
    android:paddingTop="20dp"
    >

    <View
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/colorAccent"
        />


</LinearLayout>

+2
source

Try using FrameLayout to store items inside the root LinearLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/paymentbottomsheet_view"
android:orientation="vertical"
android:background="#fff"
android:layout_width="match_parent"
android:layout_height="215dp"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<FrameLayout
    android:paddingLeft="20dp"
    android:paddingRight="20dp"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent">
//Host another linear layout here to hold your elements.
</FrameLayout>
</LinearLayout>
0
source

All Articles