Android里有两个类
android.view.GestureDetector
android.view.GestureDetector.SimpleOnGestureListener

(另外android.widget.Gallery好像是更牛xOnGestureListener

1

新建一个类继承SimpleOnGestureListenerHahaGestureDetectorListener
可以实现以下event事件。

boolean  onDoubleTap(MotionEvent e)
解释:双击的第二下Touch down时触发

boolean  onDoubleTapEvent(MotionEvent e)
解释:双击的第二下Touch downup都会触发,可用e.getAction()区分。

boolean  onDown(MotionEvent e)
解释:Touch down时触发

boolean  onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
解释:Touch了滑动一点距离后,up时触发。

void  onLongPress(MotionEvent e)
解释:Touch了不移动一直Touch down时触发

boolean  onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
解释:Touch了滑动时触发。

void  onShowPress(MotionEvent e)
解释:Touch了还没有滑动时触发
(与onDownonLongPress比较
onDown
只要Touch down一定立刻触发。

Touchdown后过一会没有滑动先触发onShowPress再是onLongPress

所以Touchdown后一直不滑动,onDown->onShowPress->onLongPress这个顺序触发。


boolean  onSingleTapConfirmed(MotionEvent e)
boolean  onSingleTapUp(MotionEvent e)
解释:上面这两个函数都是在touch down后又没有滑动(onScroll),又没有长按(onLongPress),然后Touchup时触发。

点击一下非常快的(不滑动)Touchup
onDown->onSingleTapUp->onSingleTapConfirmed

点击一下稍微慢点的(不滑动)Touchup
onDown->onShowPress->onSingleTapUp->onSingleTapConfirmed


2
)在view的新建一个GestureDetector的对象。
构造函数里
gestureDetector = new GestureDetector(new HahaGestureDetectorListener());

然后在ViewonTouchEvent里以下这样用,就可以在刚才1)弄的事件里写自己的代码了。
@Override
public boolean onTouchEvent(MotionEvent event) {
    gestureDetector.onTouchEvent(event);
}