Android 无法将 FAB 按钮锚定到 BottomSheet

标签 android button floating-action-button

我正在尝试将 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/

相关文章:

html按钮样式

Android float 操作按钮打开小 View

android - 如何以编程方式删除 fab 的布局 anchor_property?

android - 布局宽度等于高度

android - 在两个 ViewPager 小部件的连接处添加 fab Button

android - 在 Play Store android 中发布应用程序

android - 如何在未显示上下文菜单时停止将长按作为短按处理

java - 如何保持HttpClient Connection Keep-Alive?

java - 无法使用 Mockito 2 模拟最终的 Kotlin 类

javascript - HTML5 Canvas 上的多个事件监听器