Android将锚点设置为底部表格

时间:2016-07-04 03:31:19

标签: android anchor 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" />

我将FAB添加为CoordinateLayout的直接子项,并将底部工作表的id设置为FAB的layout_anchor并设置其layout_anchorGravity。但它不起作用。FAB不会移动。

3 个答案:

答案 0 :(得分:3)

我遇到了同样的问题,我找到了这个答案:https://stackoverflow.com/a/37068484/4142087

如果您将代码更改为:

,它将起作用
app:layout_anchorGravity="top|end"

答案 1 :(得分:0)

试试这个:

<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" />

答案 2 :(得分:0)

这对我有用。只需确保它在协调器布局之内即可。

    <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" />