9

I'm trying to attach a FAB button to the BottomSheet view like Google Maps does. However I cannot make it work,

this is the code of the FAB button:

 <android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email"
    app:layout_anchor="@+id/nestedscrollview" --> BottomSheet view ID
    app:layout_anchorGravity="bottom|end"
    app:elevation="4dp"
    />

and this is the code of the BottomSheet View

<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedscrollview"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
tools:context="com.pub.uac.ui.location.LocationActivity"
android:background="@color/background_white_trasnparent"
 > 
... 
</...
Jose M Lechon
  • 5,766
  • 6
  • 44
  • 60

1 Answers1

9

It depends on what you mean by "cannot make it work" and also what you try to achieve.

Does it work better if you set on the FAB:

  app:layout_anchorGravity="top|end"

You used "bottom" instead of "top", so the FAB will not be pushed by the bottom sheet, it will stay at the bottom. With "top" it should at least follow the sheet.

Vincent Hiribarren
  • 5,254
  • 2
  • 41
  • 65
  • 4
    Thank you, this helped me. But my FAB is now half obscured by my bottom sheet. Is there another setting for `layout_anchorGravity` I can use such that the **bottom** of my anchored view is on **top** of my bottom sheet? – Kevin Cronly May 23 '18 at 02:35
  • You need to set the `elevetion` of both the bottom sheet and your FAB so that the FAB has a higher elevation – Aden Diamond Oct 18 '19 at 12:53
  • And it seems that you need to use the `app` namespace when you do that – Aden Diamond Oct 18 '19 at 12:59