The Touch processing in Android is very easy to use. Collect some information and share it as follows:
Android has two classes
Android. View. gesturedetector
Android. View. gesturedetector. simpleongesturelistener
1) create a class that inherits the simpleongesturelistener and hahagesturedetectorlistener class to implement the following Event Events.
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 is triggered immediately as long as the touch is 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
2) create a gesturedetector object in view.
Constructor
Gesturedetector = new gesturedetector (New hahagesturedetectorlistener ());
Use the following code in ontouchevent of view to write your own code in the event 1 just now.
@ Override
Public Boolean ontouchevent (motionevent event ){
Gesturedetector. ontouchevent (event );
}