Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – Drawer Layout采用触摸事件而不是导航窗格的元素大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的 android项目包含2个导航抽屉.一个来自右侧,另一个来自左侧.使用此按钮单击按钮打开:

if (mDrawerLayout.isDrawerOpen(mRightDrawerView))
    mDrawerLayout.closeDrawer(mRightDrawerView);
mDrawerLayout.openDrawer(mLeftDrawerView);

两个抽屉都有自定义布局,使用以下定义:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://scheR_422_11845@as.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>

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

我也用过:

@H_297_7@mDrawerLayout.setDrawerLockmode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); mDrawerLayout.requestDisallowInterceptTouchEvent(true);

我不希望抽屉里面的触摸事件关闭.

我也试过更改抽屉布局的“可点击”属性.但没用.

任何帮助都非常感谢.谢谢

解决方法

可能为时已晚,无法回答你的问题,但它会帮助其他人,那些面临同样问题的人……

将Clickable’true’设置为包含的布局,即左右抽屉.可点击事件消耗了触摸.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://scheR_422_11845@as.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>

大佬总结

以上是大佬教程为你收集整理的android – Drawer Layout采用触摸事件而不是导航窗格的元素全部内容,希望文章能够帮你解决android – Drawer Layout采用触摸事件而不是导航窗格的元素所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。