Android 将 anchor 设置为 Bottom Sheets

标签 android anchor bottom-sheet

我想为我的 Bottom Sheet 设置一个 anchor :

<!-- 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 的直接子级,并将 Bottom Sheet 的 ID 设置为 FAB 的 layout_anchor 并设置其 layout_anchorGravity。但它不起作用。FAB 不会移动。

最佳答案

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

如果您将代码更改为这样,它将起作用:

app:layout_anchorGravity="top|end"

关于Android 将 anchor 设置为 Bottom Sheets,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38176573/

相关文章:

android - react native : Unable to download JS bundle from the Dev Server

jquery - 对 li 项内的 anchor 进行排序,而不对嵌套列表进行排序

android - 透明背景不适用于 Bottom Sheet

android - 如何从RecyclerView读取数据并在BottomSheet中发送

android - 在 Android 设备中播放

android - 如何显示设备主要联系人查看器以显示一个联系人的电话号码

Jquery或CSS在 anchor 跳转/滚动上突出显示div

android - Jetpack Compose 扩展 BottomSheetScaffold 的 BottomSheet 仅在重组后有效

android - 'LibraryExtension' 类型的扩展不存在

html - 如何控制 anchor 着陆位置