12/18/2022 0 Comments Android multitouchMotionEvent provides a method to get the length of this list: int getHistorySize() īut this provides this method, there are no other overloads, so you can’t get the length of the history track list of a certain finger’s slide this time through pointerIndex! This can be solved with only one for loop. The first question has already been mentioned, mainly the second parameter.īecause HistoricalX is a list, we need to read one by one through the index, and the second pos parameter is the index, but only if we know the length of the list. The first parameter, pointerIndex, is easy to solve. The method signature is as follows: float getHistoricalX(int pointerIndex, int pos) Second, because MotionEvent will package multiple consecutive sliding trajectories into one MotionEvent, we need to use getHistoricalX to get the historical trajectory of this sliding. First, listen to the two events of ACTION_DOWN and ACTION_POINTER_DOWN, get the PointerId of the new finger here, traverse all the fingers in the ACTION_MOVE event, and then compare PointerId can be either. But when God closes the door, he will definitely open a window. The first is how to accurately track the sliding trajectory of a finger, because as mentioned above, ACTION_MOVE cannot obtain ActionIndex. To achieve this effect, there are two main issues to consider: The picture above is the effect when swiping four fingers at the same time. Here I will make a DrawView for drawing finger movement trajectory, and it can track the trajectory of multiple fingers at the same time. Through the above introduction, we have roughly understood some key points of multi-touch, and now let’s apply them in practice. If we want to get the click point position of the event, when we get the coordinates through the getX()/ getY() method, we can only get the position of the first finger, but these two methods provide an overload: float getX(int pointerIndex) float getY(int pointerIndex) Use This value is used to get more content of the event. PointerIndex is obtained through findPointerIndex(int), the parameter is PointerId. For the same finger, the PointerId is fixed throughout the process from pressing to lifting.Īlso note that this value may be reused, for example, a finger with an id of 0 may also have an id of 0 when a finger is re-pressed after it has been lifted. The PointerId is obtained through the getPointerId(int) method, and the parameter is ActionIndex. We need to make a comprehensive judgment in combination with other events. The ACTION_MOVE event cannot accurately obtain the value. In particular, it should be noted that this method is only valid for the ACTION_POINTER_DOWN and ACTION_POINTER_UP events. It seems that the only purpose of ActionIndex is to get the PointerId. In addition, for the same finger, the value of ActionIndex may change as the finger is pressed and lifted, so we cannot use it to identify a finger. For example, when we monitor the finger lift, we may want to know which finger is lifted, then it can be judged by ActionIndex. So when dealing with multi-finger touch, our onTouch method can generally be written like this:ĪctionIndex can be obtained directly through the getActionIndex method, which can be roughly understood as describing the number of fingers that the current event occurs on. It should be noted that the above two types cannot be obtained by using the MotionEvent#getAction method as before, and need to use getActionMasked. MotionEvent.ACTION_POINTER_UP When one finger on the screen is lifted, there are still other fingers on the screen.MotionEvent.ACTION_POINTER_DOWN A finger already exists on the screen before the tap.So for multi-finger touch, in addition to the above-mentioned common event types, we also need to pay attention to two other event types: MotionEvent.ACTION_CANCEL event blocked.MotionEvent.ACTION_MOVE A finger is swiping on the screen.MotionEvent.ACTION_UP The last finger leaves the screen.MotionEvent.ACTION_DOWN Tap the screen with the first finger. Without considering multiple fingers, we generally only focus on the following event types: Generally speaking, we judge the type of input event by judging the action of MotionEvent, so as to make corresponding processing. We can override the onTouchEvent method in View, or use the setOnTouchListener method to handle touch events.įirst, let’s take a look at how to determine the event type of multi-finger touch. Multi-finger touch refers to monitoring the touch events of multiple fingers.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |