Android 浮动操作按钮停留在工具栏和显示片段的框架之间

Android 浮动操作按钮停留在工具栏和显示片段的框架之间,android,android-fragments,drawerlayout,android-coordinatorlayout,floating-action-button,Android,Android Fragments,Drawerlayout,Android Coordinatorlayout,Floating Action Button,我可以把晶圆厂按钮完美地放在布局的右下角。但是我想把FAB按钮放在工具栏和框架布局的交叉点上,我用它来处理片段 下面是我的activity_main.xml,它是用抽屉布局设计的。我已经尝试过CoordinatorLayout,但是在布局中的当前帧中,我无法按此链接所示放置FAB按钮 或 My activity_main.xml <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.andro

我可以把晶圆厂按钮完美地放在布局的右下角。但是我想把FAB按钮放在工具栏和框架布局的交叉点上,我用它来处理片段

下面是我的activity_main.xml,它是用抽屉布局设计的。我已经尝试过CoordinatorLayout,但是在布局中的当前帧中,我无法按此链接所示放置FAB按钮

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

但我无法确定应该将显示片段数据的FrameLayout放在哪里

谢谢Danail参考教程,它提供了一些帮助

现在,FAB在工具栏和片段之间显示,如我所愿

更新的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">

<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,并显示在图像链接中。

指南中有有用的信息。请仔细查看“在标题中嵌入FloatingActionButton”部分

作为总结: 您应该使用晶圆厂的
layout\u锚定
layout\u锚定
属性。在您的情况下,工具栏将是“锚定”,您应该使用
layout\u anchorGravity=“bottom | right | end”