zoukankan      html  css  js  c++  java
  • Android setOnTouchListener识别滑动手势

     1 setOnTouchListener(new OnTouchListener() {
     2             private float startX, startY, offsetX, offsetY;
     3 
     4             @Override
     5             public boolean onTouch(View v, MotionEvent event) {
     6                 switch (event.getAction()) {
     7                 case MotionEvent.ACTION_DOWN:
     8                     startX = event.getX();
     9                     startY = event.getY();
    10                     break;
    11                 case MotionEvent.ACTION_UP:
    12                     offsetX = event.getX() - startX;
    13                     offsetY = event.getY() - startY;
    14                     if (Math.abs(offsetX) > Math.abs(offsetY)) {
    15                         if (offsetX < -5) { // left
    16                             swipeLeft();
    17                         } else if (offsetX > 5) { // right
    18                             swipeRight();
    19                         }
    20                     } else {
    21                         if (offsetY < -5) { // up
    22                             swipeUp();
    23                         } else if (offsetY > 5) { // down
    24                             swipeDown();
    25                         }
    26                     }
    27                     break;
    28                 default:
    29                     break;
    30                 }
    31                 return true;
    32             }
    33         });
  • 相关阅读:
    linux终端发送邮件
    ubuntu交换Caps 和 ESC
    pycharm快捷键
    python catch socket timeout
    pgsql restart
    python re.sub
    文件写入与缓存
    HTTP协议再分析
    leetcode-45
    Java的锁
  • 原文地址:https://www.cnblogs.com/stareblankly/p/5006340.html
Copyright © 2011-2022 走看看