What's the difference between ACTION_CANCEL and ACTION_UP in MotionEvent?

社会主义新天地 提交于 2019-12-20 12:17:30

问题


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?


回答1:


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.




回答2:


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 using onInterceptTouchEvent() which returned true as a result system finished propagating the touch event.

Please take a look at a diagram



来源:https://stackoverflow.com/questions/5240719/whats-the-difference-between-action-cancel-and-action-up-in-motionevent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!