zoukankan      html  css  js  c++  java
  • GestureDetector手势识别的各个方法

    package com.example.velocity;
    
    import android.support.v7.app.ActionBarActivity;
    import android.os.Bundle;
    import android.view.GestureDetector;
    import android.view.GestureDetector.OnDoubleTapListener;
    import android.view.GestureDetector.OnGestureListener;
    import android.view.MotionEvent;
    import android.view.View;
    import android.view.View.OnTouchListener;
    import android.widget.RelativeLayout;
    
    public class MainActivity extends ActionBarActivity implements OnGestureListener, OnDoubleTapListener {
        private RelativeLayout rl;
        private GestureDetector gd; 
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            rl = (RelativeLayout) findViewById(R.id.rl);
            gd = new GestureDetector(this);
            gd.setOnDoubleTapListener(this);
            rl.setOnTouchListener(new OnTouchListener() {
    
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    boolean onTouchEvent = gd.onTouchEvent(event);
                    return onTouchEvent;
                }
            });
        }
    
        
        @Override
        public boolean onDown(MotionEvent e) {
            // TODO Auto-generated method stub
            System.out.println("down");
            return true;
        }
    
        @Override
        public void onShowPress(MotionEvent e) {
            // TODO Auto-generated method stub
            System.out.println("没松开或者拖动");
        }
    
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            System.out.println("单击行为");
            return true;
        }
        //滑动中触发
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
                float distanceY) {
    //        System.out.println("onScroll");
    //        if(e1.getRawX()-e2.getRawX()<0){
    //            System.out.println("右滑");
    //        }else if(e1.getRawX()-e2.getRawX()>0){
    //            System.out.println("左滑");
    //        }
            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) {
            if(e1.getRawX()-e2.getRawX()<-300){
                System.out.println("右滑");
            }else if(e1.getRawX()-e2.getRawX()>300){
                System.out.println("左滑");
            }
            return true;
        }
    
        
        //严格的单击行为
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            // TODO Auto-generated method stub
            return false;
        }
        //双击,不可能和onSingleTapConfirmed共同
        @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;
        }
    }
  • 相关阅读:
    iOS开发那些事-iOS6苹果地图有用开发
    Partition List -- LeetCode
    C++11:强类型枚举(enum)
    数据绑定(八)使用Binding的RelativeSource
    对于流程优化的处理器架构
    Linux/UNIX流程关系
    《炉石传说》建筑设计欣赏(6):卡&amp;在执行数据时,组织能力
    采用truelicense进行Java规划license控制 扩展可以验证后,license 开始结束日期,验证绑定一个给定的mac住址
    [Linux]scp 命令远程复制
    从头开始编写项目Makefile(八):型号规则
  • 原文地址:https://www.cnblogs.com/84126858jmz/p/5457446.html
Copyright © 2011-2022 走看看