onInterceptTouchEvent没有收到ACTION_MOVE [英] onInterceptTouchEvent never receives action_move
问题描述
我有onInterceptTouchEvent的覆盖(自定义的ViewGroup)。它接收ACTION_DOWN但从来没有收到ACTION_MOVE。这是我的理解是,除非它返回真,就应该接收所有MotionEvents。
I have a custom ViewGroup with an override of onInterceptTouchEvent(). It receives ACTION_DOWN but never receives ACTION_MOVE. It is my understanding that, unless it returns "true", it should receive all MotionEvents.
该ViewGroup中包含两个观点,一个ImageView的和网格布局。
The ViewGroup contains two views, an ImageView and a GridLayout.
我的拦截code是:
@Override
public boolean onInterceptTouchEvent(MotionEvent ev)
{
final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK)
{
case MotionEvent.ACTION_DOWN:
logD ("DDV Intercept DOWN");
break;
case MotionEvent.ACTION_POINTER_DOWN:
logD ("DDV Intercept P DOWN"); // logD: shell around Log.d()
break;
case MotionEvent.ACTION_MOVE:
logD ("DDV Intercept MOVE");
break;
case MotionEvent.ACTION_UP:
logD ("DDV Intercept UP");
break;
case MotionEvent.ACTION_POINTER_UP:
logD ("DDV Intercept P UP " + ev.getActionIndex());
break;
case MotionEvent.ACTION_CANCEL:
logD ("DDV Intercept CANCEL");
break;
default:
logD ("DDV Intercept " + (action & MotionEvent.ACTION_MASK));
}
return false;
}
我也有onTouch code返回除了在ACTION_MOVE一例虚假的;然而,这就是所谓的只为ACTION_DOWN被调用;因此它只返回false。
I also have code for onTouch that returns false except for one case in ACTION_MOVE; however, it's called only for ACTION_DOWN is called; thus it only return false.
推荐答案
这是比这更复杂一些。首先,你需要重写 onTouchEvent()
和处理有 ACTION_DOWN
和移动
事件了。然后发生以下情况。
It's a bit more complicated than that. First of all you need to override onTouchEvent()
and handle there ACTION_DOWN
and MOVE
events too. Then the following happens.
-
ACTION_DOWN
事件被分派到onInterceptTouchEvent()
第一。您应该返回假
从那里。 - 现在,有两种情况:
- 如果有下
ACTION_DONW
视图树事件的位置,然后ACTION_DOWN
事件都遵循没有触及的看法达事件被分派到onTouchEvent()
。你必须返回真正
从那里。只有这样,你会收到跟进发送到onTouchEvent()
方法事件。独立您是否返回真正
或假
,onInterceptTouchEvent()
将不会收到任何跟进事件了。 - 如果有一个可触摸视图,则所有事件将被分派到
onInterceptTouchEvent()
(包括ACTION_MOVE
事件)。你需要返回真正
从那里,当你发现你的姿态。一旦你返回真正
从这里开始,可触摸视图,将获得ACTION_CANCEL
事件和接下来的所有事件将被分派到onTouchEvent()
方法。
- 如果有下
ACTION_DOWN
event gets dispatched toonInterceptTouchEvent()
first. You should returnfalse
from there.- Now there are two cases:
- If there is no touchable view underneath
ACTION_DONW
event's location in the view tree, thenACTION_DOWN
event and all follow up events get dispatched toonTouchEvent()
. You must returntrue
from there. Only then you will receive follow up events sent toonTouchEvent()
method. Independently on whether you returntrue
orfalse
,onInterceptTouchEvent()
will not receive any follow up events anymore. - If there is a touchable view, then all events will be dispatched to
onInterceptTouchEvent()
(includingACTION_MOVE
events). You need to returntrue
from there, when you detect your gesture. Once you returntrue
from here, touchable view will will receiveACTION_CANCEL
event and all further events will be dispatched toonTouchEvent()
method.
- If there is no touchable view underneath
希望这有助于。
这篇关于onInterceptTouchEvent没有收到ACTION_MOVE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!