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。

  • 相关阅读:
    datalist的用法
    SQL级联删除——删除主表同时删除从表——同时删除具有主外键关系的表
    js
    回调机制
    JS原型链
    多线程请求乌云链接
    Python高频技巧总结[基础篇]
    批量文本读取URL获取正常访问且保留对应IP
    Django基础之视图
    Django框架简介
  • 原文地址:https://www.cnblogs.com/rfheh/p/4164448.html
Copyright © 2011-2022 走看看