1. 程式人生 > >DrawerLayout抽屜佈局item點選事件失效原因之一

DrawerLayout抽屜佈局item點選事件失效原因之一

最近使用抽屜佈局
DrawerLayout出現一個問題如下 程式碼描述 點選事件失效
<?xml version="1.0" encoding="utf-8"?>
<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"> <android.support.design.widget.NavigationView android:id="@+id/nav_view" android:layout_width="match_parent" android:layout_height=
"match_parent" android:layout_gravity="start" android:fitsSystemWindows="true" app:menu="@menu/activity_main_drawer" /> <include android:id="@+id/include1" layout="@layout/app_bar_main" android:layout_width="match_parent" android:layout_height=
"wrap_content" /> <include android:id="@+id/include2" layout="@layout/chfd_list" android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="invisible" /> </android.support.v4.widget.DrawerLayout>

 

 

 
後來通過了解
 
DrawerLayout瞭解到 
DrawerLayout佈局子佈局擺放有明確規定先後順序
修改後為 

 
<?xml version="1.0" encoding="utf-8"?>
<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
        android:id="@+id/include1"
        layout="@layout/app_bar_main"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:menu="@menu/activity_main_drawer" />
    <include
        android:id="@+id/include2"
        layout="@layout/chfd_list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="invisible"
        />
</android.support.v4.widget.DrawerLayout>
點選事件就有反應了