Usage: First let the specified activity implement Android.view.OnGestureListener, and then add Ontouchlistener on the view you need to call Gesturedetector, Setlongclickable (true) can be followed.
Such as:
Customview.setontouchlistner (Xxxlistener);
Customview.setlongclickable (TRUE);
You can then set the gesture you want in the Onfling method.
Onfling Method Parameter Explanation:
Onfling (motionevent E1, motionevent E2, float velocityx,float velocityy)
Official explanation:
Notified of a fling event when it occurs with the initial in down and the MotionEvent
matching up MotionEvent
. The calculated velocity is supplied along, the X and Y axis in pixels per second.
Specified by:Onfling (...) inongesturelistener
-
Parameters:
-
E1 The first down motion event, that started the fling.
-
E2 The move motion event triggered the current onfling.
-
Velocityx The velocity of this fling measured in pixels per second along the X axis.
-
velocityy The velocity of this fling measured in pixels per second along the Y axis.
-
Returns:
-
True if the event is consumed, else false
General meaning:
E1 represents an event that is triggered by the moment the finger is pressed,
E2 represents an event triggered when the finger is not bouncing and moving
The remaining two parameters roughly mean the number of pixels per second moving in the X, y direction.
So, by E1 and E2, you can create a judging condition for gestures.
Simple left and right swipe gesture code:
@Overridepublic boolean onfling (motionevent E1, motionevent E2, float velocityx,float velocityy) {//TODO auto-generated m Ethod stubtoif (E1.getx () > E2.getx ()) {log.i ("msg", "<<<<<<<<<");} else {log.i ("msg", "& Gt;>>>>>>>> ");} Toast.maketext (This, "Fling", 0). Show (); return false;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Simple ways to use Android swipe gestures