我正在尝试将 FAB 按钮附加到 BottomSheet View ,就像 Google map 所做的那样。但是我无法让它工作,
这是 FAB 按钮的代码:
<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/nestedscrollview" --> BottomSheet view ID
app:layout_anchorGravity="bottom|end"
app:elevation="4dp"
/>
这是 BottomSheet View 的代码
<android.support.v4.widget.NestedScrollView
android:id="@+id/nestedscrollview"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
tools:context="com.pub.uac.ui.location.LocationActivity"
android:background="@color/background_white_trasnparent"
>
...
</...
最佳答案
这取决于您所说的“无法使其工作”的含义以及您尝试实现的目标。
在 FAB 上设置是否效果更好:
app:layout_anchorGravity="top|end"
您使用“bottom”而不是“top”,因此 FAB 不会被 bottom sheet 插入,它会留在底部。对于“top”,它至少应该跟在工作表之后。
关于Android 无法将 FAB 按钮锚定到 BottomSheet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36958023/