Reputation: 1546
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.
Upvotes: 3
Views: 6489
Reputation: 1
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" />
Upvotes: 0
Reputation: 4327
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"
Upvotes: 3
Reputation: 1350
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" />
Upvotes: 0