Boolean ondoubletap (motionevent E)
Explanation: triggered when the second touch is down under double-click
Boolean ondoubletapevent (motionevent E)
Explanation: Double-click triggers both touch down and up, which can be distinguished by E. getaction.
Boolean ondown (motionevent E)
Explanation: triggered when touch is down
Boolean onfling (motionevent E1, motionevent E2, float velocityx, float velocityy)
Explanation: Touch is triggered when it is up after sliding a little distance.
Void onlongpress (motionevent E)
Explanation: triggered when touch is down without moving
Boolean onscroll (motionevent E1, motionevent E2, float distancex, float distancey)
Explanation: It is triggered when sliding is reached.
Void onshowpress (motionevent E)
Explanation: triggered when touch is not sliding
(Compared with ondown and onlongpress
Ondown must be triggered immediately as long as touch down.
After touchdown, onshowpress is triggered before onlongpress after a while without sliding.
Therefore, it does not slide after touchdown. ondown-> onshowpress-> onlongpress is triggered in this order.
Boolean onsingletapconfirmed (motionevent E)
Boolean onsingletapup (motionevent E)
Explanation: the above two functions are triggered when the touch is down without moving (onscroll) or long-pressed (onlongpress.
Click very fast (do not slide) touchup:
Ondown-> onsingletapup-> onsingletapconfirmed
Click a slightly slower (do not slide) touchup:
Ondown-> onshowpress-> onsingletapup-> onsingletapconfirmed
With so many response methods, we can more easily respond to user touch operations and correspond to various actions. How to use this class is actually very simple. Create a gesturedetector object in view. Constructor
Gesturedetector = new gesturedetector (New selfgesturedetectorlistener ());
You can use the following in ontouchevent of the view to write your own data in the gesturedetector event.Code.
@ Override
Public Boolean ontouchevent (motionevent event ){
Gesturedetector. ontouchevent (event );
}
For the ontouchevent method above, we can directly determine the motionevent type. For gesture movement, we only need to capture action_move. Through the motionevent E1, motionevent E2, float distancex, float distancey can be used to obtain operation changes.
For example, distancex> 0 moves to the right, distancex <0 moves to the left, distancey> 0 scrolls Up, And distancey <0 scrolls down. During the test, we can encapsulate this class. When each method is triggered, logcat is used to print the action and X, and Y coordinates to understand the actual situation and perform more in-depth and complex gesture detection, the android development network will be written next time.