zoukankan      html  css  js  c++  java
  • Android Gesture 手势识别

    手势识别

    实现OnGestureListener, OnTouchListener接口

    class MyView extend LinearLayout implements OnGestureListener, OnTouchListener {
    
        public MyView(Context context) {
            this.setOnTouchListener(this);// 将本类绑定触屏监听器
            GestureDetector gd = new GestureDetector(this);
        }
        
        //先经过gd.onTouchEvent(event)事件判断,
        //执行手势则不执行父类onTouch(View v, MotionEvent event)事件
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return gd.onTouchEvent(event);
        }
        
        // --------------以下是使用OnGestureListener手势监听的时候重写的函数---------
        /**
         * @以下方法中的参数解释:
         * @e1:第1个是 ACTION_DOWN MotionEvent 按下的动作
         * @e2:后一个是ACTION_UP MotionEvent 抬起的动作(这里要看下备注5的解释)
         * @velocityX:X轴上的移动速度,像素/秒
         * @velocityY:Y轴上的移动速度,像素/秒
         */
        @Override
        public boolean onDown(MotionEvent e) {
            // ACTION_DOWN
            return false;
        }
        @Override
        // ACTION_DOWN 、短按不移动
        public void onShowPress(MotionEvent e) {
        }
        
        @Override
        // ACTION_DOWN 、长按不滑动
        public void onLongPress(MotionEvent e) {
        }
        
        @Override
        // ACTION_DOWN 、慢滑动
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
                float distanceY) {
            return false;
        }
        
        @Override
        // ACTION_DOWN 、快滑动、 ACTION_UP
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                float velocityY) {
            v_str.add("onFling");
            //-------e1是MotionEvent.ACTION_DOWN, e2是MotionEvent.ACTION_UP----------
            // if(e1.getAction()==MotionEvent.ACTION_MOVE){
            // v_str.add("onFling");
            // }else if(e1.getAction()==MotionEvent.ACTION_DOWN){
            // v_str.add("onFling");
            // }else if(e1.getAction()==MotionEvent.ACTION_UP){
            // v_str.add("onFling");
            // }
            // if(e2.getAction()==MotionEvent.ACTION_MOVE){
            // v_str.add("onFling");
            // }else if(e2.getAction()==MotionEvent.ACTION_DOWN){
            // v_str.add("onFling");
            // }else if(e2.getAction()==MotionEvent.ACTION_UP){
            // v_str.add("onFling");
            // }
            return false;
        }
        @Override
        // 短按ACTION_DOWN、ACTION_UP
        public boolean onSingleTapUp(MotionEvent e) {
            return false;
        }
    }

    这只是一个简单的例子,Android Simples中有个完整的例子:Gestures Builder。

  • 相关阅读:
    Android基础之项目结构分析
    串口调试,提示the given port name does not start with COM/com异常解决办法,,发现是打印机在搞怪
    C# 通过URL获取图片并显示在PictureBox上的方法
    学习资料集合
    C#语音朗读文本 — TTS的实现
    SQL SERVER 2008安装错误(is not a valid login or you do have permission)
    函数调用导致堆栈不对称。原因可能是托管的 PInvoke 签名与非托管的目标签名不匹配。
    SerialPort使用
    Javascript函数的几种写法
    JS验证图片格式和大小并预览
  • 原文地址:https://www.cnblogs.com/rfheh/p/4164448.html
Copyright © 2011-2022 走看看