PointerIndex versus id in android

自闭症网瘾萝莉.ら 提交于 2020-07-06 13:29:28

问题


I m referring to some websites like http://developer.android.com/reference/android/view/MotionEvent.html http://www.vogella.com/tutorials/AndroidTouch/article.html to learn MotionEvent for designing User Interface. The problem is i am getting confused with terminologies like pointerIndex,Id ,getActionIndex, getActionMasked and other important methods related to MotionEvent.


回答1:


Motion events describe movements in terms of an action code and a set of axis values.The action code specifies the state change that occurred such as a pointer going down or up.

Each pointer has a unique id that is assigned when it first goes down (indicated by ACTION_DOWN or ACTION_POINTER_DOWN). A pointer id remains valid until the pointer eventually goes up (indicated by ACTION_UP or ACTION_POINTER_UP) or when the gesture is canceled (indicated by ACTION_CANCEL).

the pointer index of a pointer can change from one event to the next but the pointer id of a pointer is guaranteed to remain constant as long as the pointer remains active.




回答2:


  • Pointer index tells us which pointer in the current set of pointers the event is for

  • Pointer ID is a unique ID assigned to every pointer

The pointer index of a pointer may change, but its ID will remain the same. This is best explained with an example.

Say you have a pointer on the screen, and then touch the screen with a second pointer. Each of these pointers will have their ids and indices. Say you now remove the first pointer.

Alas! The secondary pointer now becomes the primary pointer! So its index will be changed to that of the previous pointer that was just removed i.e. its index has changed from 1 to 0. But its id will remain the same.




回答3:


From pg 609, Pro Android 2, Issue 2:

MotionEvent object contains information for pointers starting at index 0 and going up to the number of fingers being reported in that object. The pointer index always starts at 0. If there are three fingers being reported, pointer index will be 0, 1, 2. Calls to methods such as getX() must include the pointer index for the finger you want information about. Pointer IDs are integer values representing which finger is being tracked. Pointer IDs start with 0 for the first finger down, but don't always start at 0 when fingers are coming and going on the screen. Think of the pointer ID as the name of that finger while it is being tracked by Android.

For example, imagine a pair of touch sequences for two fingers, starting with finger 1 down, then finger 2 down, then finger 1 up, then finger 2 up. The first finger down will get pointer ID 0. The second finger down will get pointer ID 1. Once the first finger goes up, finger 2 will still be associated with pointer ID 1. Whereas the pointer index for finger 2 becomes 0, because the pointer index always starts at 0.

In this example, pointer ID 1 starts as pointer index 1 when it goes down, and then shifts to pointer index 0 once finger 1 leaves the screen.

Your apps will use pointer IDs to link together the events associated to a particular finger even as other fingers are involved




回答4:


A motion event can contain multiple fingers. This is how multi-touch is done. Each finger down is called a pointer. Each pointer has a unique id, and will use that id throughout the series of motion events in the touch. In the motion event, there's a list of pointers. Each index of the array references 1 pointer. The ids are NOT always in the same indexes, they can be moved around.

Each motion event except a MOVE will have an action index. The action index is the pointer index that caused the event. (Moves don't have one because multiple fingers could have moved). You can use this to find what is the new finger that touched down or was lifted up.

getActionMasked returns the type of event that happened- a down, an up, a move, etc. The reason you need to call this is because Android did something silly and used the variable to hold 2 values using some tricks. You can ignore that, you just need to know to call this function to get the type.



来源:https://stackoverflow.com/questions/22434036/pointerindex-versus-id-in-android

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