Search code examples
androidandroid-coordinatorlayoutandroid-bottomsheetdialog

Android BottomSheet expand to bottom of another view


I'm trying to make this bottom sheet only expand to the bottom of another view but haven't been able to figure it out. I'd like the locations_list_sheet to expand to the bottom of view1.

I've tried setting the offset, bottomSheet.setExpandedOffset(48) but no luck with that. I've also tried setting a margin to the top of the bottom sheet layout, but that didn't look right either.

<layout xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">

    <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <View
            android:id="@+id/view1"
            android:layout_width="match_parent"
            android:layout_height="48dp"
            android:background="@android:color/transparent" />

        <include
            android:id="@+id/map_content"
            layout="@layout/content_locations_stoneco" />

        <include
            android:id="@+id/locations_list_content"
            layout="@layout/bottom_sheet_locations" />

    </androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>

Layout


Solution

  • I don't know which particular layout you are using as bottom sheet I think it must be in one of those included layouts...

    add an attribute android:translationY="48dp" for the bottom sheet layout

        <LinearLayout
                android:layout_width="match_parent"
                android:id="@+id/botto_sheet"
                android:translationY="48dp"
                android:background="@color/colorPrimary"          
                app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
                android:layout_height="match_parent"/>
    

    What it does is basically it will push the view to down... just like margin but kinda different.

    Note: I don't know whether it's the correct way to do this but it does the job ...Suggestions are always welcome

    BTW you can add top margin also both will work