2016-04-30 61 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不會被底片推,它會留在底部。使用「頂部」時,至少應該跟隨表單。