我可以將FAB按鈕完美地放在佈局的右下角。但我希望FAB按鈕被放置在工具欄和框架佈局的交叉點處,我正在使用它作爲片段。浮動動作按鈕留在工具欄和框架之間,顯示片段
下面是我的activity_main.xml,它是用DrawerLayout設計的。我曾嘗試與CoordinatorLayout但一些如何與我目前的佈局框架內,可以如在這個環節上我不能放在FAB按鈕
http://i.stack.imgur.com/6RjOq.jpg
或
http://i.stack.imgur.com/xCxE0.png
我activity_main.xml中
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/viewA">
<LinearLayout
android:id="@+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
</LinearLayout>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@+id/container_body"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginRight="10dp"
android:layout_marginBottom="16dp"
app:fabSize="normal"
android:src="@mipmap/ic_action_stop"
app:backgroundTint="@color/colorPrimaryDark"
app:rippleColor="#F06292"
app:elevation="6dp"
app:pressedTranslationZ="12dp"/>
</FrameLayout>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer"
/>
我不想在container_body中顯示的片段中滾動內容,但只希望製作按鈕顯示工具欄和框架的中間右側。
我特地到其他計算器後 How can I add the new "Floating Action Button" between two widgets/layouts
但我無法弄清楚,我應該把FrameLayout裏顯示的分段數據。
謝謝Danail參考教程給了一些幫助。
現在FAB按照我的需要在工具欄和片段之間顯示。
更新activity_main.xml中低於
SOLUTION
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="150dp">
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/viewA"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<LinearLayout
android:id="@+id/viewB"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<FrameLayout
android:id="@+id/container_body"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12dp"
android:clickable="true"
android:src="@mipmap/ic_action_play"
app:layout_anchor="@id/toolbar"
app:layout_anchorGravity="bottom|right|end"
app:fabSize="normal"
app:backgroundTint="@color/colorPrimaryDark"
app:rippleColor="#F06292"
app:elevation="6dp"
app:pressedTranslationZ="12dp"/>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer"
/>
這被示出根據需要和在圖像鏈接所示FAB。