版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34928991/article/details/73467198
最近使用抽屉布局
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>点击事件就有反应了