您好我試圖簡單地將我的內容放在工具欄下面,但是當我運行我的應用程序時,當它應該低于它時,一些內容隱藏在它后面.
我已經閱讀了關于使用框架布局來嘗試將其分開但我已經陷入困境.我目前正在使用隨軟件提供的基本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