4.30

所花时间(包括上课):1.5

打码量(行):150

博客量(篇):1

了解到知识点:学习手势检测

 

 public class MyGestureView extends View {

 

    private GestureDetector gestureDetector;

 

    public MyGestureView(Context context) {

        super(context);

        init();

    }

 

    public MyGestureView(Context context, @Nullable AttributeSet attrs) {

        super(context, attrs);

        init();

    }

 

    private void init() {

        gestureDetector = new GestureDetector(getContext(), new MyGestureListener());

        setOnTouchListener(new View.OnTouchListener() {

            @Override

            public boolean onTouch(View v, MotionEvent event) {

                return gestureDetector.onTouchEvent(event);

            }

        });

    }

 

    private class MyGestureListener extends GestureDetector.SimpleOnGestureListener {

 

        @Override

        public boolean onSingleTapConfirmed(MotionEvent e) {

            // 单击事件处理逻辑

            return true;

        }

 

        @Override

        public void onLongPress(MotionEvent e) {

            // 长按事件处理逻辑

        }

 

        @Override

        public boolean onDoubleTap(MotionEvent e) {

            // 双击事件处理逻辑

            return true;

        }

 

        @Override

        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

            // 滑动事件处理逻辑

            return true;

        }

 

        @Override

        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

            // 快速滑动事件处理逻辑

            return true;

        }

 

        @Override

        public boolean onDown(MotionEvent e) {

            // 按下事件处理逻辑

            return true;

        }

    }

}

posted @ 2024-04-30 19:05  赵千万  阅读(3)  评论(0编辑  收藏  举报