抽屉布局采用触摸事件而不是导航窗格的元素

Lub*_*bna 6 android android-layout navigation-drawer drawerlayout

我的 Android 项目包含 2 个导航抽屉。一个从右侧开始,另一个从左侧开始。单击按钮即可打开它:

if (mDrawerLayout.isDrawerOpen(mRightDrawerView))
    mDrawerLayout.closeDrawer(mRightDrawerView);
mDrawerLayout.openDrawer(mLeftDrawerView);
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" >

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

<include
    android:id="@+id/left_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    layout="@layout/menu_panel" />

<include
    android:id="@+id/right_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    layout="@layout/search_panel" />

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

问题是:当我打开抽屉并尝试捕获其单击事件时,(抽屉布局中有按钮和文本视图)抽屉会关闭而不是响应单击事件。

我也用过:

mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
mDrawerLayout.requestDisallowInterceptTouchEvent(true);
Run Code Online (Sandbox Code Playgroud)

我不希望抽屉在其内部的触摸事件发生时关闭。

我还尝试更改抽屉布局的“可点击”属性。但没有用。

非常感谢任何帮助。谢谢

Man*_*ish 2

可能现在回答你的问题已经太晚了,但这会帮助其他人,那些和你面临同样问题的人。

将 Clickable 设置为“true”到您包含的布局,即左抽屉和右抽屉。可点击事件消耗触摸。

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

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

<include
    android:id="@+id/left_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:clickable="true"
    layout="@layout/menu_panel" />

<include
    android:id="@+id/right_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:clickable="true"
    layout="@layout/search_panel" />

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