本文介绍了Android的不能固定FAB按钮BottomSheet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个FAB按钮连接到像谷歌地图是否BottomSheet视图。不过,我不能让它工作,

这是FAB按钮code:

 < android.support.design.widget.FloatingActionButton
    机器人:ID =@ + ID / FAB
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_margin =@扪/ fab_margin
    机器人:SRC =@机器人:可绘制/ ic_dialog_email
    应用:layout_anchor =@ + ID / nestedscrollview - > BottomSheet视图ID
    应用:layout_anchorGravity =底部|结束
    应用:海拔=4DP
    />

这就是BottomSheet查看

的code

 < android.support.v4.widget.NestedScrollView
机器人:ID =@ + ID / nestedscrollview
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
应用:layout_behavior =android.support.design.widget.BottomSheetBehavior
工具:上下文=com.pub.uac.ui.location.LocationActivity
机器人:背景=@彩色/ background_white_trasnparent
 >
...
< / ...


解决方案

这取决于你的意思是不能让工作是什么,你也试图达到的目标。

它的工作更好,如果你在FAB设置:

 应用:layout_anchorGravity =顶|结束

您使用的底部,而不是顶,所以FAB不会由底部片被推动,它会留在底部。随着顶,它至少应该遵循表。

I'm trying to attach a FAB button to the BottomSheet view like Google Maps does. However I cannot make it work,

this is the code of the FAB button:

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

and this is the code of the 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"
 >
...
</...
解决方案

It depends on what you mean by "cannot make it work" and also what you try to achieve.

Does it work better if you set on the FAB:

  app:layout_anchorGravity="top|end"

You used "bottom" instead of "top", so the FAB will not be pushed by the bottom sheet, it will stay at the bottom. With "top" it should at least follow the sheet.

这篇关于Android的不能固定FAB按钮BottomSheet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-11 03:20