手势类--GestureDetector的使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_28946307/article/details/51473754

其中个的方法

  1. onContextClick(MotionEvent e):上下文点击手势。
  2. onDoubleTap(MotionEvent e):双击手势。
  3. onDoubleTapEvent(MotionEvent e):双击按下和抬起分别产生点击事件手势。
  4. onDown(MotionEvent e):单击手势。
  5. onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY):滑动手势,这个要
  6. onScroll区别:onFling是滑动后,事件响应;onScroll是手指滑动时,控件也跟着滑动,同时响应。
  7. onLongPress(MotionEvent e):长按手势。
  8. onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY):拖动手势。
  9. onShowPress(MotionEvent e):按下时响应事件。
  10. onSingleTapConfirmed(MotionEvent e):单击手势。
public class MainActivity extends AppCompatActivity {

    private GestureDetector gestureDetector;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        gestureDetector=new GestureDetector(this,simpleOnGestureListener);
    }


    @Override
    public boolean onTouchEvent(MotionEvent event) {
        gestureDetector.onTouchEvent(event);
        return super.onTouchEvent(event);
    }

    GestureDetector.SimpleOnGestureListener simpleOnGestureListener=new GestureDetector.SimpleOnGestureListener(){
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            Log.d("MainActivity","双击事件");
            return super.onDoubleTap(e);
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            Log.d("MainActivity","惯性滑动事件");
            return super.onFling(e1, e2, velocityX, velocityY);
        }

        @Override
        public void onLongPress(MotionEvent e) {
            super.onLongPress(e);
            Log.d("MainActivity","长按事件");
        }
    };
}

猜你喜欢

转载自blog.csdn.net/qq_28946307/article/details/51473754