导航抽屉布局以及包含布局

Rob*_*Rob 3 android android-layout navigation-drawer

我认为我的问题实际上很简单,但是我不知道该如何解决。一个工作正常的导航抽屉,其代码如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp" >

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
            android:id="@+id/category_list_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </ListView>

    </FrameLayout>

    <!-- The navigation drawer -->
    <ListView 
        android:id="@+id/left_drawer"
        android:entries="@array/features"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:choiceMode="singleChoice"
        android:divider="@null"
        android:background="#E0E0E0"
        android:dividerHeight="0dp"
        />    
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

但是当我尝试使用include时,像这样:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp" >

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <ListView
            android:id="@+id/category_list_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </ListView>

    </FrameLayout>

    <!-- The navigation drawer -->
    <include layout="@layout/drawer"/>

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

当我在框架布局中单击列表视图中的项目时,没有任何反应。

这是我要包括的抽屉布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="5dp" >

    <!-- The navigation drawer -->
    <ListView 
        android:id="@+id/left_drawer"
        android:entries="@array/features"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:choiceMode="singleChoice"
        android:divider="@null"
        android:background="#E0E0E0"
        android:dividerHeight="0dp"
        />

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

感谢您的帮助!

Dav*_*and 5

您包含的布局声明了第二个android.support.v4.widget.DrawerLayout,不应该声明。只需ListView在您包含的布局中声明一个即可。

文件cabinet.xml

<?xml version="1.0" encoding="utf-8"?>
<ListView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/left_drawer"
    android:entries="@array/features"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    android:choiceMode="singleChoice"
    android:divider="@null"
    android:background="#E0E0E0"
    android:dividerHeight="0dp"
    />    
Run Code Online (Sandbox Code Playgroud)