• 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;
        }
    }
  • 相关阅读:
    css中!important的用法
    mysql分区
    js 随机生成信用卡号
    js argument
    lnmp
    php的mcrypt
    php gd
    php socket
    最优服务次序问题 水 NOJ1254
    众数问题 NOJ 1207
  • 原文地址:https://www.cnblogs.com/84126858jmz/p/5457446.html
Copyright © 2020-2023  润新知