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;
        }
    }
  • 相关阅读:
    android中设置快捷键方法setShortcut参数的说明
    LayoutInflater
    Java读取文本文件中文乱码问题 .转载
    eclipse+ADT 进行android应用签名详解
    实验课表
    程序员技术练级攻略
    超过4000长度的字符串如何添加到oracle数据库中
    Hive sql创建表以及插入分区表
    Hive Sql 时间格式化处理
    oracle如何查询分区表所占空间大小
  • 原文地址:https://www.cnblogs.com/84126858jmz/p/5457446.html
Copyright © 2011-2022 走看看