【发布时间】:2021-08-09 14:22:28
【问题描述】:
我的 APP 有问题,我有一个 BottomSheet,我正在添加一个 FAB,FAB 应该始终位于 BottomSheet 的顶部,所以我在 FAB 中添加了底部边距,问题是,一旦 BottomSheet 展开,FAB 就会锚定到 bottomsheet 而没有初始底部边距。
我怎样才能使FAB 始终位于顶部?
这是我的代码:
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="2dp"
android:padding="2dp"
android:scrollbars="vertical"
tools:listitem="@layout/recyclerview_pterm" />
<include
layout="@layout/bottom_sheet_pterm" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="76dp"
android:clickable="true"
android:focusable="true"
app:layout_anchor="@+id/bottomSheet"
app:layout_anchorGravity="top|end"
app:srcCompat="@drawable/ic_covid"
android:contentDescription="@string/verifica_gp" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
下面是它的样子:
【问题讨论】:
标签: android android-layout floating-action-button bottom-sheet