【发布时间】:2016-02-04 13:12:58
【问题描述】:
由于我为抽屉式导航使用了固定菜单,因此我尝试在 DrawerLayout 的第二个子项中使用 LinearLayout 而不是 RecyclerView/ListView 以使其更易于编码。但结果是全屏线性布局。有没有办法在 DrawerLayout 中使用常规视图(如线性布局)?
<android.support.v4.widget.DrawerLayout 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:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello world"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bye world"/>
</LinearLayout>
【问题讨论】:
-
"有没有办法在 DrawerLayout 中使用常规视图(如线性布局)?" - 是的。您必须正确设置您的
DrawerLayout及其子Views。 -
如何设置 DrawerLayout 以使用 LinearLayout 而不是 RecyclerView?
-
与
RecyclerView相同,替换为LinearLayout。 -
抽屉布局的 XML 是什么样的?里面不是有风景吗?
-
您唯一应该记住的是:第一个孩子是您的主要内容,第二个孩子是您的抽屉内容(据我所知,可以是任何视图组)。
标签: android android-layout android-linearlayout android-recyclerview navigation-drawer