Android:ACTION_UP 和 ACTION_POINTER_UP 之间的区别

发布于 2024-10-04 09:04:39 字数 342 浏览 2 评论 0原文

仅从 android 文档来看,我并不真正理解 ACTION_UPACTION_POINTER_UP 之间的区别。 http://developer.android.com/reference/android/view/ MotionEvent.html#ACTION_DOWN

基本上我想捕获当一根手指从屏幕上释放时的事件(即使另一根手指可能仍在触摸它)

From the android doc alone I dont really understand the difference between ACTION_UP and ACTION_POINTER_UP.
http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_DOWN

Basically I want to capture the event when one finger is released from the screen (even if another one may still be touching it)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

携君以终年 2024-10-11 09:04:39

如果您还没有阅读过,请从这里开始: http ://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html

Android 根据手势来考虑触摸事件。这种意义上的手势包括从第一根手指触摸屏幕到最后一根手指离开屏幕的所有事件。单个手势的整个事件序列始终发送到在初始 ACTION_DOWN 期间选取的同一视图,除非父级由于某种原因拦截了事件流。如果父进程拦截子进程的事件流,子进程将收到 ACTION_CANCEL

如果您正在处理多点触控事件,请始终使用 getActionMasked() 返回的值来确定操作。如果您不需要多点触控或使用较旧的平台版本,则可以忽略 ACTION_POINTER_* 事件。

  • ACTION_DOWN 适用于触摸屏幕的第一根手指。这将启动手势。该手指的指针数据始终位于 MotionEvent 中的索引 0 处。
  • ACTION_POINTER_DOWN 用于在第一个手指之外进入屏幕的额外手指。该手指的指针数据位于 getActionIndex() 返回的索引处。
  • 当手指离开屏幕但至少有一根手指仍在触摸屏幕时发送 ACTION_POINTER_UP。关于抬起的手指的最后一个数据样本位于 getActionIndex() 返回的索引处。
  • 当最后一个手指离开屏幕时发送ACTION_UP。关于抬起的手指的最后一个数据样本位于索引 0 处。这将结束手势。
  • ACTION_CANCEL 表示整个手势由于某种原因被中止。手势就此结束。

Start here if you haven't read it already: http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html

Android thinks about touch events in terms of gestures. A gesture in this sense includes all events from the first finger that touches the screen to the last finger that leaves the screen. A single gesture's entire event sequence is always sent to the same view that was picked during the initial ACTION_DOWN unless a parent intercepts the event stream for some reason. If a parent intercepts a child's event stream, the child will get ACTION_CANCEL.

If you're working with multitouch events, always use the value returned by getActionMasked() to determine the action. If you don't need multitouch or are working with an older platform version, you can ignore the ACTION_POINTER_* events.

  • ACTION_DOWN is for the first finger that touches the screen. This starts the gesture. The pointer data for this finger is always at index 0 in the MotionEvent.
  • ACTION_POINTER_DOWN is for extra fingers that enter the screen beyond the first. The pointer data for this finger is at the index returned by getActionIndex().
  • ACTION_POINTER_UP is sent when a finger leaves the screen but at least one finger is still touching it. The last data sample about the finger that went up is at the index returned by getActionIndex().
  • ACTION_UP is sent when the last finger leaves the screen. The last data sample about the finger that went up is at index 0. This ends the gesture.
  • ACTION_CANCEL means the entire gesture was aborted for some reason. This ends the gesture.
年少掌心 2024-10-11 09:04:39

我相信它源于多点触控的添加,ACTION_UP 自 API Level 1 以来就已经存在,但 ACTION_POINTER_UP 是在添加多点触控时在 API Level 5 中添加的。

您获得的结果将取决于您调用的方法,getAction() 将返回 ACTION_UP,而 getActionMasked() 将返回 ACTION_POINTER_UP 还允许您调用 getActionIndex() 来找出刚刚引发了哪个多点触摸指针。我想这就是你想做的。

I believe it stemmed from Multi-touch being added in, ACTION_UP has been in since API Level 1, but ACTION_POINTER_UP was added in API Level 5 when multi-touch was added.

The result you get will depend on which method you are calling, getAction() would return ACTION_UP whereas getActionMasked() would give ACTION_POINTER_UP but also allow you to call getActionIndex() to find out which of the multi-touch pointers has just been raised. I think this is what you want to do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文