是什么导致了 Android 中的 MotionEvent.ACTION_CANCEL?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11960861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What causes a MotionEvent.ACTION_CANCEL in Android?
提问by Phil
I am working through debugging some touch handling stuff on Android, and am trying to figure out why the MotionEvent sent to my View's onTouchListener
contains a cancelaction. I have not been able to find any documentation on its cause, and was hoping someone could point me in the right direction for debugging this problem - error codes, source code, or some general knowledge.
我正在调试 Android 上的一些触摸处理内容,并试图弄清楚为什么发送到我的视图的 MotionEventonTouchListener
包含取消操作。我无法找到有关其原因的任何文档,并希望有人能指出我调试此问题的正确方向 - 错误代码、源代码或一些一般知识。
回答by 0gravity
Is this what you are looking for:
这是你想要的:
"ACTION_CANCEL occurs when the parent takes possession of the motion, for example when the user has dragged enough across a list view that it will start scrolling instead of letting you press the buttons inside of it. You can find out more about it at the viewgroup documentation: onInterceptTouchEvent."
“ACTION_CANCEL 发生在父级控制动作时,例如当用户在列表视图中拖动足够多的时候它会开始滚动而不是让你按下里面的按钮。你可以在视图组中找到更多关于它的信息文档:onInterceptTouchEvent。”
Hope that is the answer you are looking for:
希望这是您正在寻找的答案:
Resources: Motion Event, Stack Overflow.
回答by Marc Alexander
All you need is to call
你只需要打电话
requestDisallowInterceptTouchEvent(true);
on the parent view, like this -
在父视图上,像这样 -
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch(motionEvent.getActio){
}
return false;
}
Source: onInterceptTouchEvent, onTouchEvent only see ACTION_DOWN
回答by yoAlex5
ACTION_CANCEL
is triggered by ancestor to notify all descendants that they lost onTouch
control and it's will be responsible for handling the next onTouch
event. Usually it is caused when a descendant returned true in onTouch
or onTouchEvent
method but after that, during the next of touch event of gesture, an ancestor returned true in onInterceptTouchEvent()
ACTION_CANCEL
由祖先触发通知所有后代他们失去了onTouch
控制,它将负责处理下一个onTouch
事件。通常是由后代在onTouch
或onTouchEvent
方法中返回真引起的,但之后,在手势的下一个触摸事件中,祖先在或方法中返回真引起onInterceptTouchEvent()
回答by Chitranshu Asthana
When the drag moves out of view rect, you get ACTION_CANCEL
当拖动移出视野矩形时,您将获得 ACTION_CANCEL