3

I wanna set an anchor to my Bottom Sheet:

<!-- bottom sheets -->
<LinearLayout
    android:id="@+id/bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:orientation="vertical"
    android:padding="10dp"
    app:layout_behavior="@string/bottom_sheet_behavior">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="bottom sheets test! " />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="bottom sheets content! bottom sheets content! bottom sheets content! bottom sheets content! bottom sheets content! bottom sheets content! bottom sheets content! bottom sheets content! bottom sheets content! bottom sheets content! bottom sheets content! bottom sheets content! " />
</LinearLayout>

<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/bottom_sheet"
    app:layout_anchorGravity="bottom|end" />

I add the FAB as the direct child of the CoordinateLayout and set the bottom sheet's id to the FAB's layout_anchor and set its layout_anchorGravity. But it doesn't work.The FAB won't move.

Allen Vork
  • 1,536
  • 3
  • 16
  • 29

3 Answers3

3

I faced same problem and I found this answer: https://stackoverflow.com/a/37068484/4142087

It will work, if you will change your code to this:

app:layout_anchorGravity="top|end"
Community
  • 1
  • 1
Anton Shkurenko
  • 4,301
  • 5
  • 29
  • 64
  • Thx.It works.But I find that when I drag the anchor, the bottomsheet doesn't move.When i drag the bottom sheet, it works well.Do I miss something? – Allen Vork Jul 15 '16 at 09:25
  • @AllenVork looks like no, it works as expected. Only bottom sheet is draggable here, anchor point means only that view will follow another view it's anchored to. – Anton Shkurenko Jul 15 '16 at 11:29
0

Try this:

<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/bottom_sheet"
    app:layout_anchorGravity="end" />
Sagar Jogadia
  • 1,330
  • 1
  • 16
  • 25
0

This works for me. Just make sure it's within a Coordinator Layout.

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        app:fabSize="normal"
        app:srcCompat="@drawable/ic_fab"
        app:layout_anchor="@id/bottom_sheet"
        app:layout_anchorGravity="top|end" />