Android的 - 拦截和传球上的所有触摸事件事件、Android

2023-09-05 23:52:19 作者:故乡的原风景

我有一个叠加的ViewGroup这是我想用来显示的效果,当用户与应用程序交互的屏幕尺寸,但仍传递onTouch事件,任何潜在的意见。

I have an overlay ViewGroup that is the size of the screen which I want to use to show an effect when the user interacts with the app, but still passes the onTouch event to any underlying views.

我intrested在所有MotionEvents(不只是下),所以onInterceptTouchEvent()在这里并不适用,如果我返回true我的叠加会消耗掉所有的活动,如果假只会收到DOWN事件(同applys到onTouch )。

I am intrested in all MotionEvents (not just DOWN), so onInterceptTouchEvent() does not apply here as if i return true my overlay will consume all events, and if false will only receive the DOWN events (the same applys to onTouch).

我想我可以覆盖Activitys dispatchTouchEvent(MotionEvent EV)和我的叠加调用自定义触摸事件,但这并没有转化取决于我的看法的位置输入COORDS的效果(例如所有事件将通过出现以上20或以下的实际触摸所以PX作为系统栏不考虑)。

I thought I could override the Activitys dispatchTouchEvent(MotionEvent ev) and call a custom touch event in my overlay, but this has the effect of not translating the input coords depending on the position of my view (for example all events will pass appear to be happening 20 or so px below the actual touch as the system bar is not taken into account).

任何指针将是巨大的,THX!

Any pointers would be great, thx!

推荐答案

我解决了这个与非完美的解决方案,但工作在这种情况下。

I solved this with a non perfect solution but works in this situation.

我创造了另一个ViewGroup中包含一个可点击的孩子有宽度和高度设置为FILL_PARENT(这是我加入效果前要求),并覆盖onIntercept ...()。在onIntercept ......我传递事件到我的叠加,以自定义onDoubleTouch(MotionEvent)方法,并做了相关处理存在,而无需中断输入事件的路由平台,让底层的ViewGroup行为是正常的。

I created another ViewGroup which contains a clickable child which has width and height set to fill_parent (this was my requirement before adding the effects) and have overridden onIntercept...(). In onIntercept... I pass the event on to my overlay view to a custom onDoubleTouch(MotionEvent) method and do the relevant processing there, without interrupting the platforms routing of input events and letting the underlying viewgroup act as normal.

轻松!