直接代码,很简单
- public class GestureTestActivity extends Activity {
- private GestureDetector gestureDetector;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- gestureDetector=new GestureDetector(this, new GestureListener());
- gestureDetector.setIsLongpressEnabled(false);
- Log.i("test", ((new GestureListener()) instanceof OnDoubleTapListener)+"");
- }
- @Override
- public boolean onTouchEvent(MotionEvent event) {
- //经过测试,Android的多点触摸最多支持两点的触摸。
- //将该Activity的touch事件交给GestureDetector处理
- Log.i("count", event.getPointerCount()+"");
- float x1=event.getX(0);
- float y1=event.getY(0);
- float x2=event.getX(1);
- float y2=event.getY(1);
- float x3=event.getX(2);
- float y3=event.getY(2);
- Log.i("test", "start the test!!!");
- Log.i("test", x1+"");
- Log.i("test", y1+"");
- Log.i("test", "-------------------------------");
- Log.i("test", x2+"");
- Log.i("test", y2+"");
- Log.i("test", "-------------------------------");
- Log.i("test", x3+"");
- Log.i("test", y3+"");
- Log.i("test", "the next test!!!");
- return gestureDetector.onTouchEvent(event);
- }
- //继承于SimpleOnGestureListener,实现所有事件监听方法
- private class GestureListener extends SimpleOnGestureListener{
- @Override
- public boolean onDoubleTap(MotionEvent e) {
- Log.i("test", "onDoubleTap");
- return super.onDoubleTap(e);
- }
- @Override
- public boolean onDoubleTapEvent(MotionEvent e) {
- Log.i("test", "onDoubleTapEvent");
- return super.onDoubleTapEvent(e);
- }
- @Override
- public boolean onDown(MotionEvent e) {
- Log.i("test", "onDown");
- return super.onDown(e);
- }
- @Override
- public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
- Log.i("test", "onFling");
- return super.onFling(e1, e2, velocityX, velocityY);
- }
- @Override
- public void onLongPress(MotionEvent e) {
- Log.i("test", "onLongPress");
- super.onLongPress(e);
- }
- @Override
- public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
- Log.i("test", "onScroll");
- return super.onScroll(e1, e2, distanceX, distanceY);
- }
- @Override
- public void onShowPress(MotionEvent e) {
- Log.i("test", "onShowPress");
- super.onShowPress(e);
- }
- @Override
- public boolean onSingleTapConfirmed(MotionEvent e) {
- Log.i("test", "onSingleTapConfirmed");
- return super.onSingleTapConfirmed(e);
- }
- @Override
- public boolean onSingleTapUp(MotionEvent e) {
- Log.i("test", "onSingleTapUp");
- return super.onSingleTapUp(e);
- }
- }
- }