首页 > 解决方案 > 在工具栏和底栏之间放置 FrameLayout

问题描述

我完全知道如何使用相对布局或约束布局来做到这一点。但我没有设法用协调器布局做到这一点

看起来框架布局与顶部和底部工具栏重叠。

我需要相对布局中的“下方”或“上方”标签。与协调员进行这种布局的正确方法是什么?

我玩了 'app:layout_anchorGravity' 但我没能把它弄好。

我要做的就是在框架布局内显示片段而不重叠。我不希望我的片段与工具栏重叠,我希望介于两者之间

从图中可以看出,项目编号 0,项目编号 1 没有显示,它在工具栏的后面,还有项目编号 21、22 谢谢

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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="match_parent">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?android:attr/actionBarSize"
            android:background="@color/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    </android.support.design.widget.AppBarLayout>


    <FrameLayout
        android:id="@+id/framelayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
         />

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_gravity="bottom"
        android:id="@+id/appbar_bottom"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <com.aurelhubert.ahbottomnavigation.AHBottomNavigation
            android:id="@+id/bottombar_navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:fitsSystemWindows="true" />
    </android.support.design.widget.AppBarLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|end"
        android:layout_margin="@dimen/fab_margin"
        app:layout_anchor="@id/appbar_bottom"
        app:layout_anchorGravity="top|end"
        app:srcCompat="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

在此处输入图像描述

标签: androidandroid-coordinatorlayout

解决方案


请在此处检查更新的布局...它应该可以解决您的问题。

<?xml version="1.0" encoding="utf-8"?>
<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="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">


        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:theme="@style/AppTheme.AppBarOverlay">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?android:attr/actionBarSize"
                android:background="@color/colorPrimary"
                app:popupTheme="@style/AppTheme.PopupOverlay" />
        </android.support.design.widget.AppBarLayout>


        <FrameLayout
            android:id="@+id/framelayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/appbar_bottom"
            android:layout_below="@+id/app_bar" />

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar_bottom"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_gravity="bottom"
            android:theme="@style/AppTheme.AppBarOverlay">

            <com.aurelhubert.ahbottomnavigation.AHBottomNavigation
                android:id="@+id/bottombar_navigation"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:fitsSystemWindows="true" />
        </android.support.design.widget.AppBarLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_gravity="top|end"
            android:layout_margin="@dimen/fab_margin"
            app:layout_anchor="@id/appbar_bottom"
            app:layout_anchorGravity="top|end"
            app:srcCompat="@android:drawable/ic_dialog_email" />
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

在此处输入图像描述


推荐阅读