android屏幕监控上下左右滑动

在 onFling方法中实现左右滑动:

  1. public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
  2.                         float distanceY) {
  3.                 float y1 = e1.getY(), y2 = e2.getY();
  4.                 if (y1 -y2 > 120) {  
  5.                         if (mDirection != SOUTH) {
  6.                             mNextDirection = NORTH;
  7.                     }
  8.                 Log.d(this.getClass().getName(), "To UP" + "(" + y1
  9.                                         + "," + y2 + ")");
  10.                         return (true);
  11.         } else if (y1 - y2 < -120) {  
  12.                 if (mDirection != NORTH) {
  13.                             mNextDirection = SOUTH;
  14.                     }
  15.                 Log.d(this.getClass().getName(), "To Down" + "(" + y1
  16.                                         + "," + y2 + ")");
  17.                         return (true);
  18.         }  
  19.                 return false;
  20.         }
复制代码
在 onScroll 方法中实现上下滑动:
  1. public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
  2.                         float velocityY) {
  3.                 Log.d("Fling", "Fling Happened!");  
  4.                 float x1 = e1.getX(), x2 = e2.getX();
  5.                 
  6.         if (x1 -x2 > 120) {  
  7.                 if (mDirection != EAST) {
  8.                                 mNextDirection = WEST;
  9.                         }
  10.                 Log.d(this.getClass().getName(), "To LEFT" + "(" + x1
  11.                                         + "," + x2 + ")");
  12.                         return (true);
  13.         } else if (x1 - x2 < -120) {  
  14.                 if (mDirection != WEST) {
  15.                                 mNextDirection = EAST;
  16.                         }
  17.                 Log.d(this.getClass().getName(), "To Right" + "(" + x1
  18.                                         + "," + x2 + ")");
  19.                         return (true);
  20.         }  
  21.         
  22.                 return false;
  23.         }
复制代码
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值