android提供ToolBar实现划动菜单的陷阱

代码如下:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <!--工具条-->
    <include layout="@layout/toolbar_main"></include>

    <android.support.v4.widget.DrawerLayout
        android:id="@+id/dl_AllLayout"

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">
        <!--内容***************一定要放在滑动菜单的下方**************-->
        <include layout="@layout/content_main"/>
        <!--滑动菜单-->
        <include layout="@layout/layout_left_menu"></include>
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

众所周知,android系统在3.0之后的support-v7包中添加了ToolBar工具条和抽屉效果:

import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;

那么在DrawerLayout中添加左滑菜单和主体内容时一定要注意优先添加,activity中的主要内容,后添加划动菜单布局。

如果顺序相反会出现,在抽屉窗口中不能响应“点击”,“划动”等任何事件;而且在activity中将抽屉菜单滑动显示出来后,无法将其用手指滑动将其隐藏(可以通过ToolBar按钮隐藏)。

因为DrawerLayout会最后去解析划动菜单,它认为DrawerLayout的最后一个儿子是滑动菜单

请广大android盆友小心此问题!!!

原文地址:https://www.cnblogs.com/zzq-include/p/5596393.html