Android提供了类GestureDetector
来完成一些简单的手势识别,实现手势识别的要点请看HelloGesture
代码:
io.github.tianshanxuester.hellogesture.HelloGesture
1
2
3
4
5
6
7
8
9
10
11
12
13
14
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hello_gesture);
mGestureDetector = new GestureDetectorCompat(this, this);
mGestureDetector.setOnDoubleTapListener(this);
}
@Override
public boolean onTouchEvent(MotionEvent event){
this.mGestureDetector.onTouchEvent(event);
// Be sure to call the superclass implementation
return super.onTouchEvent(event);
}
22、23行创建了一个GestureDetector对象,并将回调接口设置为当前Activity;27-30行响应当前Activity的手势操作事件,并将事件传递给之前定义的GestureDetector对象。
参考链接: