android – DrawerLayout阻止调用MainActivity.onTouchEvent()

android – DrawerLayout阻止调用MainActivity.onTouchEvent(),第1张

概述我有一个应用程序覆盖MainActivity的onTouchEvent(MotionEvent ev)来确定双指滑动和Pich-Open / Pinch-Close. 一切正常,直到我将DrawerLayout添加到应用程序(就像它在 Creating a Navigation Drawer中描述的那样).问题:DrawerLayout阻止在MainActivity中调用onTouchEvent( 我有一个应用程序覆盖MainActivity的ontouchEvent(MotionEvent ev)来确定双指滑动和Pich-Open / Pinch-Close.
一切正常,直到我将DrawerLayout添加到应用程序(就像它在 Creating a Navigation Drawer中描述的那样).问题:DrawerLayout阻止在MainActivity中调用ontouchEvent().

我开始编写一个CustomDrawerLayout,并尝试覆盖OnIntercepttouch()和ontouchEvent()上的DrawerLayout方法.

(我发现)将touchEvent传输到MainActivity的唯一方法:

// ontouchEvent of CustomDrawerLayout     @OverrIDe    public boolean ontouchEvent(MotionEvent ev){        // super.ontouchEvent(ev); // prevent transmission of touchEvent        return false;    }

这里的问题是抽屉没有正确打开.抽屉卡住了这篇文章中描述的内容:
DrawerLayout getting stuck on swipe.

是否可以将touchEvent传输到MainActivity来处理MultitouchDetection?或者我必须在CustomDrawerLayout中处理这个问题?

更新1

首先,我必须说,如果我从左边缘滑动,抽屉只会卡住.通过单击Actionbar中的DrawerIcon,Drawer工作正常.
touchEvent的传输使用以下代码.但只有抽屉被打开!否则不调用Activity.ontouchEvent!

// ontouchEvent of CustomDrawerLayout     @OverrIDe    public boolean ontouchEvent(MotionEvent ev){        // super.ontouchEvent(ev); // still prevents transmission of touchEvent        activity.ontouchEvent(ev);        return true;    }

通过从边缘滑动打开抽屉( – >抽屉卡住),我得到一个非常奇怪的行为:

>只是DrawerIcon可以关闭“卡住的抽屉”( – >我不希望有什么不同,因为我覆盖了CustomDrawerLayout.ontouchEvent)
>如果我通过DrawersIcon关闭被卡住的抽屉,仍会调用CustomDrawerLayout.ontouchEvent

真奇怪!为什么不调用Activity.ontouchEvent()?我怎样才能防止被卡住的抽屉?

更新2

现在我重写CustomDrawerLayout.onIntercepttouch():

@OverrIDepublic boolean onIntercepttouchEvent(MotionEvent ev){        return true;}

这样的效果是不能通过从边缘滑动来打开抽屉 – >只有DrawersIcon才能打开和关闭抽屉.但是现在touchEvent总是被传送到Activity( – >就像预期的那样工作).

但我真正想要的是通过从边缘滑动来打开抽屉的可能性并拥有我的MultiGestureDetector.这可能吗?

解决方法 稍微更新了一段时间,但在这个问题出现几天之后,最适合我的解决方案是创建一个CustomDrawerLayout.然后,将构造函数中的Context作为Activity转换,从onIntercepttouchEvent调用Activity ontouchEvent.

@OverrIDe public boolean onIntercepttouchEvent( MotionEvent ev ){    getActivity().ontouchEvent( ev );    return super.onIntercepttouchEvent( ev );}

我发现代码是一个蹩脚的黑客…但对我有用.祝好运!

总结

以上是内存溢出为你收集整理的android – DrawerLayout阻止调用MainActivity.onTouchEvent()全部内容,希望文章能够帮你解决android – DrawerLayout阻止调用MainActivity.onTouchEvent()所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1127539.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存