How to differentiate gesture and click?
I need to implem开发者_Go百科ent logic for panning surface and be able to click on it to place image, but when I'm trying to add gesture detector as simple as:
public boolean onTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
} else {
return super.onTouchEvent(event);
}
}
And when I'm starting gesture, image being placed on screen. Please help.
Check here:
Fling gesture detection on grid layout
Use the classes and interfaces from android.gesture, especially OnGestureListener. The OS takes of care of recognizing gestures.
As Hyperboreus said, use the GestureDetector.OnGestureListener
interface which you associate to your GestureDetector
instance. No need then to associate a click listener to your view and a touch listener. Specifically, use the GestureDetector.OnGestureListener.onSingleTapUp(MotionEvent)
method for detecting clicks, the GestureDetector.OnGestureListener.onFling(MotionEvent, MotionEvent, float, float)
method for detecting flings, and so on and so forth.
Remember to return true
in your implementation of the GestureDetector.OnGestureListener.onDown(MotionEvent)
method.
精彩评论