android - 在工具栏和底栏之间放置 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>
解决方案
请在此处检查更新的布局...它应该可以解决您的问题。
<?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>
推荐阅读
- javascript - 在 Node js 中不使用 Buffer 的情况下将字符串转换为 base64 的替代方法
- json - 我无法使用 Swift JSON 打印到 TableView 数据
- c# - VlcControl.TakeSnapshot 生成文件但为空
- android - Kotlin 使用协程处理改造请求
- python - 重塑阵列以重组阵列拼贴
- javascript - 如何处理 mongooe 验证错误并根据错误进一步处理
- python - 测量 xy 点的时间序列之间的相关性 - python
- android - 如何从具有 OS 11 的 Android 设备获取 mac 地址?
- build - Nextjs 在生产中所需的最小文件结构
- ios - 如何在查询中组合 2 个 json