zoukankan      html  css  js  c++  java
  • 单手指和双手指(手势探测器)

    单手指:

    •   如果想要监听单手指操作的全部操作监听(有两个接口,仅需要挑选自己需要的来实现):

      

    public class SingleGesture implements GestureDetector.OnGestureListener,GestureDetector.OnDoubleTapListener {
    
        @Override
        public boolean onDown(MotionEvent e) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public void onShowPress(MotionEvent e) {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
                float distanceY) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public void onLongPress(MotionEvent e) {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                float velocityY) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            // TODO Auto-generated method stub
            return false;
        }
    
    }
    View Code
    •   如果仅仅想要监听单手指操作的一部分简单操作的监听:
    public class SingleGesture extends GestureDetector.SimpleOnGestureListener {
    
    }

      因为SimpleOnGestureListener实现了onGestureListener接口和onDoubleTapListener接口,所以仅仅需要重写两个接口上的所需要的方法即可

        

     
    /**
         * A convenience class to extend when you only want to listen for a subset
         * of all the gestures. This implements all methods in the
         * {@link OnGestureListener} and {@link OnDoubleTapListener} but does
         * nothing and return {@code false} for all applicable methods.
         */
        public static class SimpleOnGestureListener implements OnGestureListener, OnDoubleTapListener {
            public boolean onSingleTapUp(MotionEvent e) {
                return false;
            }
    
            public void onLongPress(MotionEvent e) {
            }
    
            public boolean onScroll(MotionEvent e1, MotionEvent e2,
                    float distanceX, float distanceY) {
                return false;
            }
    
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                    float velocityY) {
                return false;
            }
    
            public void onShowPress(MotionEvent e) {
            }
    
            public boolean onDown(MotionEvent e) {
                return false;
            }
    
            public boolean onDoubleTap(MotionEvent e) {
                return false;
            }
    
            public boolean onDoubleTapEvent(MotionEvent e) {
                return false;
            }
    
            public boolean onSingleTapConfirmed(MotionEvent e) {
                return false;
            }
        }
    View Code

    双手指:

    •   如果想要监听单手指操作的全部操作监听
    public class TwoFingerGesture implements ScaleGestureDetector.OnScaleGestureListener {
    
        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean onScaleBegin(ScaleGestureDetector detector) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public void onScaleEnd(ScaleGestureDetector detector) {
            // TODO Auto-generated method stub
            
        }
    
    }
    View Code
    •   如果仅仅想要监听双手指操作的一部分简单操作的监听:
    public class TwoFingerGesture extends ScaleGestureDetector.SimpleOnScaleGestureListener {
    
    }

      

  • 相关阅读:
    怎么用js实现jq的removeClass方法
    减少事件绑定次数
    JS setAttribute兼容
    css3常用动画+动画库
    小tip: transition与visibility
    image的srcset属性
    jqeury点击空白关闭弹窗
    卡片翻转效果
    div+css 圆角加阴影
    函数
  • 原文地址:https://www.cnblogs.com/could-deng/p/5050860.html
Copyright © 2011-2022 走看看