在Android中,MotionEvent中的getAction()和getActionMasked()有什么区别? [英] In Android, what is the difference between getAction() and getActionMasked() in MotionEvent?

查看:1058
本文介绍了在Android中,MotionEvent中的getAction()和getActionMasked()有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Android中的两种方法感到困惑.它 似乎这两种方法都可以告诉您这是什么类型的事件, 即是下降事件还是上升事件.

I am confused by the two methods in Android. It seems that both methods tell you what kind of event it is, i.e., whether it is a down or up event.

我什么时候使用哪个?

public void onTouchEvent(MotionEvent e)

请不要引用该文档,因为我已阅读该文档,并且看不到任何一种方法都可以提供给我的参数.

Don't quote the documentation please, because I read it, and I don't see any parameter I can supply to either of the methods to get something different.

public final int getAction ()

public final int getActionMasked()

推荐答案

是的,它们都返回操作(上/下等),但是getAction()可能返回带有指针信息的操作,在这种情况下,事件可能有所不同. getActionMasked()将始终返回带有指针信息被屏蔽"的简单"动作(得到吗?).然后,您将在同一事件上调用getPointerIndex()以获取指针的索引.请注意,最常见的情况是在具有多个接触点(指针)的多点触控设备上.指针索引本质上是一种将事件与接触点进行匹配的方式,因此您可以区分它们.

Yes, they both return the action (up/down etc.), but getAction() may return the action with pointer information, in which case the events may be a little different. getActionMasked() will always return "simple" actions with the pointer information "masked out" (get it?). You would then call getPointerIndex() on the same event to get the index of the pointer. Note that you will most commonly see this on multi-touch devices with multiple points of contact (pointers). The pointer index is essentially a way of matching events to contact points so you can tell them apart.

这篇关于在Android中,MotionEvent中的getAction()和getActionMasked()有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆