如何在Android DrawerLayout我可以requestDisallowTouchEvents [英] How can I requestDisallowTouchEvents on Android DrawerLayout

查看:346
本文介绍了如何在Android DrawerLayout我可以requestDisallowTouchEvents的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的情况:我需要一个 GestureDetector 在我的活动拦截水平飞灰湮灭。本次活动也恰好包含 DrawerLayout

I have an instance where I need a GestureDetector in my Activity to intercept horizontal flings. This activity also happens to contain a DrawerLayout.

我遇到的问题是, DrawerLayout 拦截所有触摸事件,使得我甚至不能 requestDisallowInterceptTouchEvents 。我似乎无法永远得到触摸,甚至在活动引发这一呼吁。

The problem I'm having is that the DrawerLayout intercepts all touch events such that I can't even requestDisallowInterceptTouchEvents. I can't seem to ever get a touch even in the Activity to trigger that call.

我想打开时关闭,当抽屉从边缘处理挥笔,从任何地方,喜欢它应该。布提需要我的活动,以便能够在其他地方拦截触摸事件当抽屉被关闭。

I'd like the Drawer to handle swipes from the edge when closed, and from anywhere when opened, like it's supposed to. ButI need my activity to be able to intercept touch events elsewhere when the drawer is closed.

推荐答案

不知道,如果你解决了这一点,但请确保您onTouch(查看视图,MotionEvent motionEvent){...}方法返回true指示初始事件被处理,否则抽屉布局是会得到初始触摸启动事件和吞噬接下来那些无论你传递给requestDisallowInterceptTouchEvents什么。

Not sure if you solved this, but make sure that your onTouch(View view, MotionEvent motionEvent){...} method returns true to indicate that the initial event is handled, otherwise the drawer layout is going to get the initial touch start event and gobble the next ones no matter what you pass to requestDisallowInterceptTouchEvents.

不幸的是SDK中BasicGestureDetect示例返回从这个方法,这是罚款,在没有其他大约是窃取这些事件和你只是记录他们是假的,但如果你复制粘贴了code到应用期待它的工作(比如我),你不会得到除初始触摸启动任何东西。

Unfortunately the BasicGestureDetect example in the SDK returns false from this method, which is fine when nothing else is around to steal those events and you're just logging them, but if you copy pasted that code into your app expecting it to work (like me), you're not going to get anything except the initial touch start.

所以里面MainActivity本节从BasicGestureDetect例如:

So this section inside MainActivity from the BasicGestureDetect example:

    actionFragment.getView().setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            gd.onTouchEvent(motionEvent);
            return false;
        }
    });

而应该是:

    actionFragment.getView().setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            gd.onTouchEvent(motionEvent);
            return true;
        }
    });

这篇关于如何在Android DrawerLayout我可以requestDisallowTouchEvents的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆