2016-04-30 63 views
7

我试图将FAB按钮附加到底部视图视图,如Google地图。但是我不能让它工作,Android无法将FAB按钮锚定到底部图片

这是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" 
> 
... 
</... 
+0

在github上试试这个例子.............. https://github.com/chrisbanes/cheesesquare –

+0

我也在尝试同样的事情吗? – sector11

+0

还没有,仍然试图找出如何挂钩ID –

回答

-1

从FAB声明的代码删除--> BottomSheet view ID。这是一个不完整的评论,下面的代码还没有达到(代码是黑色的)

+0

该评论没有出现在代码中,我只在这里添加了这个问题,以帮助理解哪一个是视图。 –

+0

有一件事,你应该删除'app:layout_anchor =“@ + id/nestedscrollview”中的“+”星号并看到这个:http://stackoverflow.com/a/5025971/6275643。希望它能帮助你。 (+)错误:(45,28)找不到与给定名称相匹配的资源(位于'layout_anchor',值为'@ id/nestedscrollview')的 –

+0

。 –

6

这取决于你的意思是“不能使它工作”,也是你试图实现的。

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

app:layout_anchorGravity="top|end" 

您使用的“底部”,而不是“顶”,所以FAB不会被底片推,它会留在底部。使用“顶部”时,至少应该跟随表单。