将 FrameLayout 放在工具栏和底部栏之间
Place FrameLayout between toolbar and bottom bar
我完全知道如何使用相对布局或约束布局来做到这一点。
但是我没有设法用协调器布局来做到这一点
框架布局似乎与顶部和底部工具栏重叠。
我需要相关布局中的 'below' 或 'above' 标签。
用协调器做这种布局的正确方法是什么?
我玩过'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>
将 id 指定为工具栏
android:id="@+id/header"
并将底栏设为
android:id="@+id/footer"
现在您可以像这样放置 FrameLayout
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/footer"
android:layout_below="@id/header"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Content goes here"
android:textColor="@color/ash"
android:textSize="20sp" />
</FrameLayout>
请在此处检查更新后的布局...它应该可以解决您的问题。
<?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>
我完全知道如何使用相对布局或约束布局来做到这一点。 但是我没有设法用协调器布局来做到这一点
框架布局似乎与顶部和底部工具栏重叠。
我需要相关布局中的 'below' 或 'above' 标签。 用协调器做这种布局的正确方法是什么?
我玩过'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>
将 id 指定为工具栏
android:id="@+id/header"
并将底栏设为
android:id="@+id/footer"
现在您可以像这样放置 FrameLayout
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@id/footer"
android:layout_below="@id/header"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Content goes here"
android:textColor="@color/ash"
android:textSize="20sp" />
</FrameLayout>
请在此处检查更新后的布局...它应该可以解决您的问题。
<?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>