MotionEvent中的ACTION_CANCEL和ACTION_UP有什么区别? [英] What's the difference between ACTION_CANCEL and ACTION_UP in MotionEvent?
问题描述
我想跟踪屏幕上的手指触摸.所以我要做的是在 MotionEvent
触发 ACTION_DOWN
时开始记录位置,但是如何知道动作何时完成,在 ACTION_CANCEL
处,还是 ACTION_UP
?
I want to track a finger touch on the screen. So what I did was to start recording the position when MotionEvent
triggers ACTION_DOWN
, but how do I know when the action is finished, at ACTION_CANCEL
, or ACTION_UP
?
它们之间的确切区别是什么?
What's the exact difference between them?
推荐答案
-
ACTION_UP:手势已完成,该动作包含最终的释放位置以及自上次下移或移动事件以来的任何中间点.
ACTION_UP: A pressed gesture has finished, the motion contains the final release location as well as any intermediate points since the last down or move event.
ACTION_CANCEL:当前手势已中止.
ACTION_CANCEL: The current gesture has been aborted.
ACTION_CANCEL在父级控制动作时发生,例如,当用户在列表视图中拖动足够多时,它将开始滚动而不是让您按下其内部的按钮.您可以在视图组文档中找到有关它的更多信息: onInterceptTouchEvent .
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,否则请使用ACTION_UP.
so use ACTION_CANCEL when the action is dragged out of the parent, and ACTION_UP otherwise.
这篇关于MotionEvent中的ACTION_CANCEL和ACTION_UP有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!