-1

由于我为导航抽屉使用了固定菜单,因此我尝试在DrawerLayout的第二个子代中使用LinearLayout,而不是RecyclerView/ListView,以使代码更易于使用。但结果是全屏幕线性布局。有什么方法可以在DrawerLayout中使用常规视图(如linearlayout)?在DrawerLayout中使用LinearLayout而不是RecyclerView

<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> 

+0

向我们展示您的代码! –

+1

“在DrawerLayout中有没有任何方法可以使用常规视图(如linearlayout)?” - 是的。您必须正确设置您的'DrawerLayout'及其子'View'。 –

+0

如何设置DrawerLayout以使用LinearLayout而不是RecyclerView? –

回答

1

任何View可以充当在DrawerLayout抽屉。 DrawerLayout要将View识别为抽屉,则必须将layout_gravity属性设置为left/rightstart/end,具体取决于您希望抽屉所连接的垂直边缘。

抽屉的layout_height通常为match_parent,使得抽屉跨越DrawerLayout的整个高度,并且其通常layout_width是一种精确度量 - 例如,240dp - 保持一致的宽度,独立的其内容。

此外,抽屉View必须在DrawerLayout内最后列出才能保持正确的z顺序,否则将由内容View覆盖并且不会收到点击事件。

相关问题