There are two classes in Android
Android.view.GestureDetector
Android.view.GestureDetector.SimpleOnGestureListener
(in addition, Android.widget.Gallery seems to be more ongesturelistener of the Ox x)
1)
Create a new class to inherit Simpleongesturelistener,hahagesturedetectorlistener
The following event events can be implemented.
Boolean Ondoubletap (Motionevent e)
Explanation: Double click on the second touch down when the trigger
Boolean ondoubletapevent (Motionevent e)
Explanation: Double click down and up will trigger, and e.getaction () can be used to distinguish between the two.
Boolean Ondown (Motionevent e)
Explanation: Trigger when touching down
Boolean onfling (Motionevent E1, motionevent E2, float Velocityx, float velocityy)
Explanation: Touch it by sliding a little distance after the up is triggered.
void Onlongpress (Motionevent e)
Explanation: The touch is not moving, always touching down.
Boolean onscroll (Motionevent E1, motionevent E2, float Distancex, float distancey)
Explanation: Touch the trigger when sliding.
void Onshowpress (Motionevent e)
Explanation: Touch has not yet slipped when triggered
(Compared with ondown,onlongpress
Ondown as soon as touch down must trigger immediately.
and touchdown after a while not sliding first trigger onshowpress again is onlongpress.
So touchdown does not slide, ondown->onshowpress->onlongpress this sequence trigger.
)
Boolean onsingletapconfirmed (Motionevent e)
Boolean onsingletapup (Motionevent e)
Explanation: The above two functions are not sliding (onscroll) after touching down, without a long press (onlongpress), and then triggering when touchup.
Click on the very fast (do not slide) Touchup:
Ondown->onsingletapup->onsingletapconfirmed
Click a little slower (do not slide) Touchup:
Ondown->onshowpress->onsingletapup->onsingletapconfirmed
2 A new Gesturedetector object in view.
In the constructor function
Gesturedetector = new Gesturedetector (new Hahagesturedetectorlistener ());
Then you can write your own code in the ontouchevent of the view by using the following in the event you just made in 1.
Copy Code code as follows:
@Override
public boolean ontouchevent (Motionevent event) {
Gesturedetector.ontouchevent (event);
}
Mtouchlistener = new Ontouchlistener () {
@Override
public boolean Ontouch (View V, motionevent event) {
TODO auto-generated Method Stub
float x = event.getxprecision () *event.getx () +event.getx ();
Float y = event.getyprecision () *event.gety () +event.gety ();
Switch (event.getaction ()) {
Case Motionevent.action_down:
Break
Case Motionevent.action_move:
mtouchtimes++;
if (Mtouchtimes > Touch_times) {
According to the direction of calculation angle
if (Mcurrentorientation==deviceorientation.landscape) {
mangle = Math.todegrees (Math.atan2 (Y-480/2, x)) +90;
} else {
mangle =-math.todegrees (Math.atan2 (Y-480/2, 320-x)) +90;
}
LOG.W ("angle", "mangle:" +mangle);
}
Break
Case MOTIONEVENT.ACTION_UP:
if (Mtouchtimes > Touch_times) {
} else {
}
Mtouchtimes = 0;
Break
Default
Break
}
return true;
}
};
Mview.setontouchlistener (Mtouchlistener);