【问题标题】:how to detect finger swipe in android如何在android中检测手指滑动
【发布时间】:2014-03-09 21:21:36
【问题描述】:

我正在尝试进行手指滑动,但未检测到。我正在尝试绘制一条路径,该路径描述了手指滑动的区域,但只有当我用力滑动时,才会检测到滑动,否则未检测到

public boolean onTouchEvent(MotionEvent event) {
if (System.currentTimeMillis() - lastClick > 500) {
       lastClick = System.currentTimeMillis();
       synchronized (getHolder()) {
           int eventaction = event.getAction();
           if(event.getPressure()>0.00001||event.getSize()>0.00001)
           {

           float a,b,c;
           switch(eventaction)
           {
           case MotionEvent.ACTION_DOWN:

               xdown = event.getX();
               ydown =event.getY();
               pres=true;

               break;

           case MotionEvent.ACTION_MOVE:
               if(pres)
               {

               xmove = event.getX();
               ymove =event.getY();
               a = (float) Math.sqrt(Math.pow(xdown - xmove,2) +Math.pow( ydown - ymove,2)); 
            b=(float) (xdown-(((xdown - xmove) / a) * 150));
            c=(float) (ydown-((( ydown - ymove)/a)*150));
            move.moveTo(xdown, ydown);
            move.lineTo(b, c);
               pres=false;
               lmove=true;

               }
               break;
           case MotionEvent.ACTION_CANCEL:
           case MotionEvent.ACTION_POINTER_UP:
               move.reset();
                   xmove = 0;
                   ymove =0;
                   xdown=0;
                   ydown=0;
               lmove=false;
               pres=false;
               break;
           default:
               return true;

           }
       }
       }}
return true;

       } 

【问题讨论】:

标签: android swipe touch-event


【解决方案1】:

Android 有一个类。检查http://developer.android.com/reference/android/view/GestureDetector.html 我相信这是一种接触事件

【讨论】:

    【解决方案2】:

    在此处查看代码:Simple swipe gesture to activity tutorial?

    使用 SimpleOnGestureListener 是最简单的,如果你重写 onFling 方法就很简单/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-16
      • 2011-05-15
      • 1970-01-01
      • 1970-01-01
      • 2011-07-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多