杨子刚的博客


Android手势识别

2013-11-19

Android提供了类GestureDetector来完成一些简单的手势识别,实现手势识别的要点请看HelloGesture代码:

io.github.tianshanxuester.hellogesture.HelloGesture

18 @Override
19  protected void onCreate(Bundle savedInstanceState) {
20      super.onCreate(savedInstanceState);
21      setContentView(R.layout.activity_hello_gesture);
22      mGestureDetector = new GestureDetectorCompat(this, this);
23      mGestureDetector.setOnDoubleTapListener(this);
24  }
25  
26     @Override 
27     public boolean onTouchEvent(MotionEvent event){ 
28         this.mGestureDetector.onTouchEvent(event);
29         // Be sure to call the superclass implementation
30         return super.onTouchEvent(event);
31     }

22、23行创建了一个GestureDetector对象,并将回调接口设置为当前Activity;27-30行响应当前Activity的手势操作事件,并将事件传递给之前定义的GestureDetector对象。

参考链接: