• 为activity添加左右手势识别


    android开发中为activity添加左右手势识别。如右滑关闭当前页面

    /*
      *  for左右手势
      *  1.复制以下的内容到目标Activity
      *  2.目标Activity的onCreate()调用initGesture()
      *  3.目标Activity需implements OnTouchListener, OnGestureListener
      */
     private GestureDetector mGestureDetector;
     private int verticalMinDistance = 180;
     private int minVelocity         = 0;
     
     private void initGesture() {
         mGestureDetector = new GestureDetector((OnGestureListener) this);
     }
     
     public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
     
         if (e1.getX() - e2.getX() > verticalMinDistance && Math.abs(velocityX) > minVelocity) {
     
             // 切换Activity
             // Intent intent = new Intent(ViewSnsActivity.this, UpdateStatusActivity.class);
             // startActivity(intent);
             //Toast.makeText(this, "向左手势", Toast.LENGTH_SHORT).show();
         } else if (e2.getX() - e1.getX() > verticalMinDistance && Math.abs(velocityX) > minVelocity) {
     
             // 切换Activity
             // Intent intent = new Intent(ViewSnsActivity.this, UpdateStatusActivity.class);
             // startActivity(intent);
             //Toast.makeText(this, "向右手势", Toast.LENGTH_SHORT).show();
             finish();
             overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);
         }
     
         return false;
     }
      
     @Override
     public void onLongPress(MotionEvent arg0) {
         // TODO Auto-generated method stub
          
     }
     
     @Override
     public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
             float arg3) {
         // TODO Auto-generated method stub
         return false;
     }
     
     @Override
     public void onShowPress(MotionEvent arg0) {
         // TODO Auto-generated method stub
          
     }
     
     @Override
     public boolean onSingleTapUp(MotionEvent arg0) {
         // TODO Auto-generated method stub
         return false;
     }
     
     @Override
     public boolean onTouch(View v, MotionEvent event) {
         // TODO Auto-generated method stub
         return mGestureDetector.onTouchEvent(event);
     }
     
     @Override
     public boolean onDown(MotionEvent arg0) {
         // TODO Auto-generated method stub
         return false;
     }
      
     @Override 
     public boolean dispatchTouchEvent(MotionEvent ev) {
         mGestureDetector.onTouchEvent(ev);
         return super.dispatchTouchEvent(ev);
    }


  • 相关阅读:
    js 加密混淆工具
    postgresql 相关函数总结
    eclipse启动Tomcat时报错:严重: Exception loading sessions from persistent storage
    java sm4国密算法加密、解密
    java mail 封装工具类使用
    echarts 折线图百分比 tooltip 实例 两种方法
    开启人生的巅峰!!!
    判断是不是谷歌浏览器
    C#导出Excel的具体代码,供大家参考,具体内容请求URL
    SVN 安装后右键出现点击鼠标右键弹出错误提示:CrashHandler initialization error
  • 原文地址:https://www.cnblogs.com/slgkaifa/p/6880209.html
Copyright © 2020-2023  润新知