MotionEvent中ACTION_CANCEL和ACTION_UP有什么区别?
我想跟踪屏幕上的手指触摸。所以我所做的是开始记录 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MotionEvent:
ACTION_UP:按下手势已完成,动作包含最终释放位置以及自上次向下或移动事件以来的任何中间点。
ACTION_CANCEL:当前手势已中止。
当父级拥有该动作时,例如当用户在列表视图上拖动足够多时,它将开始滚动而不是让您按下其中的按钮时,就会发生 ACTION_CANCEL 。您可以在视图组文档中找到有关它的更多信息: onInterceptTouchEvent< /a>.
因此,当将操作拖出父级时,请使用 ACTION_CANCEL,否则使用 ACTION_UP。
MotionEvent:
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: The current gesture has been aborted.
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.
so use ACTION_CANCEL when the action is dragged out of the parent, and ACTION_UP otherwise.
一般来说,当访客完成时,
ACTION_UP
由用户触发,以明确指示用户完成了与移动的交互。另一方面,Android 系统调用
ACTION_CANCEL
来指示其中一个视图使用onInterceptTouchEvent()
获取控制权,该视图返回 true,因为系统完成了触摸事件的传播。请看一下图表
In general
ACTION_UP
is triggered by user when the guest is finished to definitely indicate that the user completed interacting with movement.On the other hand
ACTION_CANCEL
is called by Android system to indicate that one of views took control usingonInterceptTouchEvent()
which returned true as a result system finished propagating the touch event.Please take a look at a diagram