1

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

MrBovineJoni
  • 296
  • 1
  • 3
  • 15
  • A picture of what you want would be better ... to find quick solution – AgentP May 27 '20 at 15:15
  • 1
    try setting `app:behavior_peekHeight="48dp"` / use `bottomSheetBehavior.setPeekHeight(48)` as mentioned here -https://stackoverflow.com/a/35696248/6763544 – Sairaj Sawant May 27 '20 at 15:22
  • @PraveenSP added photo. I'd like the bottom sheet to expand to the bottom of the green bar at the top of the layout. Currently it expands to full screen, over top of the green bar. – MrBovineJoni May 27 '20 at 15:32

2 Answers2

3

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

AgentP
  • 6,261
  • 2
  • 31
  • 52
0

I believe this library could help you achieve what you want!

Example from site:

<com.sothree.slidinguppanel.SlidingUpPanelLayout
xmlns:sothree="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
sothree:umanoPanelHeight="68dp"
sothree:umanoShadowHeight="4dp">

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="Main Content"
    android:textSize="16sp" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center|top"
    android:text="The Awesome Sliding Up Panel"
    android:textSize="16sp" />

F.Mysir
  • 2,838
  • 28
  • 39