setOnTouchListener不叫上ViewFlipper不叫、setOnTouchListener、ViewFlipper

2023-09-05 03:43:40 作者:我是燈泡我會發光°

我要听触摸事件的viewFlipper。我已经能够听我的活动触摸事件,然后修改viewFlipper但这些事件被触发无论用户是在活动中,我需要在viewFlipper专门捕捉触摸事件。我曾尝试加入setOnTouchListener,但它不叫。我假设viewFlippers儿童(webviews)被'消耗'的触摸事件。

I want to listen to touch events for a viewFlipper. I've been able to listen to touch events in my activity and then modify the viewFlipper but these events are fired wherever the user is within the activity and I need to capture touch events specifically on the viewFlipper. I have tried adding setOnTouchListener but it is not called. I'm assuming the viewFlippers children (webviews) are 'consuming' the touch events.

一种解决办法是setOnTouchListener的每个webviews,但这种感觉就像一个黑客。有谁知道另一种方式?

One solution would be to setOnTouchListener's to each of the webviews but this feels like a hack. Does anyone know another way?

谢谢

伊恩

抱歉,如果这是一个双重职务 - 但我的previous后似乎已经消失

Sorry if this is a double post - but my previous post seems to have vanished.

推荐答案

使用 ViewGroup.onInterceptTouchEvent(MotionEvent)

您应该引用了Android文档因为它的用法是相当复杂的。

You should Reference the Android Documentation as it's usage is quite complicated.

使用的基本总结:

您这里收到触摸事件。如果你想使用它,返回true和控制将被传递给ViewFlipper的的onTouchEvent()。返回FALSE,它将继续传递给孩子。 的onTouchEvent()也应该返回true,以确保接下来的所有事件都返回到ViewFlipper的方法。孩子也会用行动 ACTION_CANCEL 接收原始事件。

You receive the touch event here. If you want to consume it, return true and control will be passed to the ViewFlipper's onTouchEvent(). Return false and it will continue to be passed to the child. onTouchEvent() should also return true to ensure all further events are returned to the ViewFlipper's method. The child will also receive the original event with the action ACTION_CANCEL.