android 内容显示栏,android – 在工具栏下显示内容

您好我试图简单地将我的内容放在工具栏下面,但是当我运行我的应用程序时,当它应该低于它时,一些内容隐藏在它后面.

我已经阅读了关于使用框架布局来尝试将其分开但我已经陷入困境.我目前正在使用随软件提供的基本android studio导航抽屉模板,并想知道我必须做出哪些更改.

我的协调员布局

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:theme="@style/AppTheme.AppBarOverlay">

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"

android:background="?attr/colorPrimary"

app:popupTheme="@style/AppTheme.PopupOverlay" />

android:id="@+id/fragment_container"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

我的抽屉布局

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:fitsSystemWindows="true"

tools:openDrawer="start">

layout="@layout/app_bar_main"

android:layout_width="match_parent"

android:layout_height="match_parent" />

android:id="@+id/nav_view"

android:layout_width="wrap_content"

android:layout_height="match_parent"

android:layout_gravity="start"

android:fitsSystemWindows="true"

app:headerLayout="@layout/nav_header_main"

app:menu="@menu/activity_main_drawer" />

我需要做出哪些改变?

解决方法:

许多ViewGroups允许他们的孩子重叠.这些包括FrameLayout,RelativeLayout,CoordinatorLayout和DrawerLayout.一个不允许其子项重叠的是LinearLayout.

你的问题的答案实际上取决于最终结果应该是什么.如果你想要一个总是在屏幕上的工具栏和它下面的一些内容,那么你根本不需要CoordinatorLayout和AppBarLayout,你可以使用一个带有两个子节点的垂直LinearLayout:

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"

... />

android:id="@+id/fragment_container"

android:layout_width="match_parent"

android:layout_height="0dp"

android:layout_weight="1"

... />

注意FrameLayout的布局属性.

如果你想在滚动内容的同时进行工具栏滚动和离开屏幕的花哨的东西,那么你需要一个AppBarLayout,你需要给你的内容区域一个特殊属性,如下所示:

android:layout_width="match_parent"

android:layout_height="wrap_content"

... >

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"

app:layout_scrollFlags="scroll"

... />

android:id="@+id/fragment_container"

android:layout_width="match_parent"

android:layout_height="match_parent"

app:layout_behavior="@string/appbar_scrolling_view_behavior"

... />

标签:android,android-toolbar,xml,android-layout,toolbar

来源: https://codeday.me/bug/20190930/1836908.html

你可能感兴趣的:(android,内容显示栏)