DrawerLayout $ MainActivity.onTouchEvent的对$ pvents电话() [英] DrawerLayout prevents call of MainActivity.onTouchEvent()

查看:167
本文介绍了DrawerLayout $ MainActivity.onTouchEvent的对$ pvents电话()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,覆盖的onTouchEvent(MotionEvent EV) MainActivity 确定<$ C $的C>两个手指划动和 PICH公开 / 捏关闭。 一切工作正常,直到我添加了 DrawerLayout 的应用程序(如它的创建导航抽屉)。问题:在 DrawerLayout prevents 的onTouchEvent的调用()在MainActivity

I have an app that overrides the onTouchEvent(MotionEvent ev) of the MainActivity to determine Two-Finger-Swipe and Pich-Open/Pinch-Close. Everything works fine until I add the DrawerLayout to the app (like it's described in Creating a Navigation Drawer). Problem: the DrawerLayout prevents the call of onTouchEvent() in the MainActivity.

我就开始写了 CustomDrawerLayout ,并尝试重写 DrawerLayout 方法 onInterceptTouch ()的onTouchEvent()

I started to write a CustomDrawerLayout, and try to override the DrawerLayout methods onInterceptTouch() and onTouchEvent().

(我发现),只有这样,才能发送的TouchEvent 的MainActivity:

The only way (I found) to transmit the TouchEvent to the MainActivity:

    // onTouchEvent of CustomDrawerLayout 
    @Override
    public boolean onTouchEvent(MotionEvent ev){
        // super.onTouchEvent(ev); // prevent transmission of TouchEvent
        return false;
    }

这里的问题是,抽屉不正确打开。抽屉stucks想在这个帖子中描述: DrawerLayout被陷在刷卡

The problem here is that the Drawer doesn't open correctly. The Drawer stucks like described in this post: DrawerLayout getting stuck on swipe.

是否有可能发送的TouchEvent 来MainActivity处理MultiTouchDetection?还是我来处理这 CustomDrawerLayout

Is it possible to transmit the TouchEvent to MainActivity to handle the MultiTouchDetection? Or do I have to handle this in CustomDrawerLayout?

更新1

首先,我必须说,抽屉只有stucks,如果我从左侧边缘轻扫。通过点击在动作条的DrawerIcon的抽屉工作正常。 的TouchEvent 传输适用于以下code。但是,只有当抽屉运行结束!否则 Activity.onTouchEvent 不叫!

First I have to say that the Drawer only stucks, if I swipe from the left edge. By clicking on the DrawerIcon in the ActionBar the Drawer works fine. Transmission of TouchEvent works with following code. But only if the Drawer is opend! Otherwise Activity.onTouchEvent isn't called!

    // onTouchEvent of CustomDrawerLayout 
    @Override
    public boolean onTouchEvent(MotionEvent ev){
        // super.onTouchEvent(ev); // still prevents transmission of TouchEvent
        activity.onTouchEvent(ev);
        return true;
    }

通过与刷卡从边缘打开抽屉( - >抽屉stucks)我得到一个非常奇怪的现象:

By opening the Drawer with a swipe from the edge (-> Drawer stucks) i get a really strange behaviour :

  • 在刚刚DrawerIcon可以关闭stucked抽屉( - >我不希望不同的东西,因为我重写 CustomDrawerLayout.onTouchEvent
  • 如果我通过DrawersIcon关闭stucked抽屉的 CustomDrawerLayout.onTouchEvent 仍称
  • just DrawerIcon can close "stucked Drawer" (-> I wouldn't expect something different because I override the CustomDrawerLayout.onTouchEvent)
  • if I close the stucked Drawer by DrawersIcon the CustomDrawerLayout.onTouchEvent is still called

那才怪!为什么 Activity.onTouchEvent()不叫?我怎样才能prevent的stucked抽屉?

Thats strange! Why Activity.onTouchEvent() isn't called? And how can I prevent the stucked Drawer?

更新2

现在我重写 CustomDrawerLayout.onInterceptTouch()

@Override
public boolean onInterceptTouchEvent(MotionEvent ev){
        return true;
}

这具有这样的抽屉不能从边缘开由轻扫的效果 - >只有DrawersIcon可以打开和关闭抽屉。但现在的的TouchEvent 总是发送到活动。( - >的作品像预期)

This has the effect that the Drawer can't be opened by a swipe from the edge -> only the DrawersIcon can open and close the Drawer. But now the TouchEvent is always transmitted to the Activity (-> that works like expected).

但我真正想要的是有possibilty从边缘打开抽屉通过刷卡有我MultiGestureDetector。这可能吗?

But what I really want is to have the possibilty to open the Drawer by a swipe from the edge AND to have my MultiGestureDetector. Is this possible?

推荐答案

一晚更新了一下,但一两天,这工作对我最好是建立一个CustomDrawerLayout的解决方案有此问题后。然后,从铸造的构造作为活动的背景下,被称为活动的onTouchEvent从onInterceptTouchEvent。

A bit of a late update, but after having this issue for a couple of days, the solution that worked best for me was creating a CustomDrawerLayout. Then, casting the Context from the constructor as an Activity, called the Activity onTouchEvent from onInterceptTouchEvent.

@Override public boolean onInterceptTouchEvent( MotionEvent ev )
{
    getActivity().onTouchEvent( ev );
    return super.onInterceptTouchEvent( ev );
}

我找到code是一个蹩脚的黑客...但我的作品。祝你好运!

I find the code to be a lame hack... but works for me. Good luck!

这篇关于DrawerLayout $ MainActivity.onTouchEvent的对$ pvents电话()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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