【问题标题】:Android Cannot anchor FAB button to BottomSheetAndroid无法将FAB按钮锚定到BottomSheet
【发布时间】:2016-04-30 17:31:10
【问题描述】:

我正在尝试像 Google 地图一样将 FAB 按钮附加到 BottomSheet 视图。但是我不能让它工作,

这是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视图的代码

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

【问题讨论】:

标签: android button floating-action-button


【解决方案1】:

这取决于您所说的“无法使其发挥作用”以及您尝试实现的目标。

如果在FAB上设置效果会更好:

  app:layout_anchorGravity="top|end"

您使用“底部”而不是“顶部”,因此 FAB 不会被底部板推动,它将停留在底部。 “top”至少应该跟在表格后面。

【讨论】:

  • 谢谢,这对我有帮助。但是我的 FAB 现在被我的底页遮住了一半。 layout_anchorGravity 是否有其他设置我可以使用这样我的锚定视图的 bottom 位于底部工作表的 top 上?
  • 您需要同时设置底部工作表和您的FAB的elevetion,以便FAB具有更高的海拔
  • 而且您在这样做时似乎需要使用app 命名空间
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-11-25
  • 1970-01-01
  • 2014-08-20
  • 1970-01-01
  • 2023-03-15
相关资源
最近更新 更多