安卓:GestureDetector不会赶上手势 [英] Android: GestureDetector won't catch Gestures

查看:131
本文介绍了安卓:GestureDetector不会赶上手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要我的程序GestureDetectors。一个精美作品,其他没有。据我可以告诉他们俩都实现了同样的方式。

I have to GestureDetectors in my program. One works beautifully, the other doesn't. As far as I can tell they're both implemented the same way.

这里的code执行不工作之一:

Here's the code for implementing the one that isn't working:

myExcuseGestureDetector = new GestureDetector(new excuseGestureDetector());
excuseView.setOnTouchListener(new View.OnTouchListener() {
    public boolean onTouch(View v, MotionEvent event) {
       if(myExcuseGestureDetector.onTouchEvent(event)){
         Log.d("Excuse Gesture Return","true");
         return true;
       }
       Log.d("Excuse Gesture Return","false");
       return false;
    }
});

然后,我有这个模块以后,它定义excuseGestureDetector

Then I have this block later which defines excuseGestureDetector

private class excuseGestureDetector extends SimpleOnGestureListener{
  @Override
     public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
   Log.d("MotionEvent","onFling");
         try {
             if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                 return false;
             // right to left swipe
             if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
              if(currExcuseNumber<currExcuseSet.size()){
               currExcuseNumber++;
               loadNextExcuse(currExcuseNumber,1);
                excuseView.setInAnimation(slideLeftExcuseIn);
                  excuseView.setOutAnimation(slideLeftExcuseOut);
                excuseView.showNext();
                return true;
              }
             }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
              if(currExcuseNumber > 1){
               loadNextExcuse(currExcuseNumber,0);
                excuseView.setInAnimation(slideRightExcuseIn);
                  excuseView.setOutAnimation(slideRightExcuseOut);
                excuseView.showPrevious();
               return true;
              }
             }
         } catch (Exception e) {
             // nothing
         }
         return false;
     }
}

无论出于何种原因,它并没有注册一扔可言。无论动画是否发生与否,该方案应打印出Log.d(MotionEvent,onFling),我试图追查并没有。我所知道的是,它并注册了某种程度的的TouchEvent已发生,因为它描绘出从我展示了首块借口姿态归来假。为什么它不会注册一扔有什么想法?

For whatever reason, it doesn't register the fling at all. Regardless of whether the animation happens or not, the program should print out the Log.d("MotionEvent","onFling") that I'm trying to trace and it doesn't. All I know is that it does register that a touchevent of some sort has occured because it does trace out "Excuse Gesture Return" "false" from the first block I showed. Any thoughts on why it won't register the fling?

推荐答案

我真的不知道为什么,但是当我把覆盖所有可能的手势在SimpleOnGestureListener它开始工作。 Apparantly它需要他们都在那里,不只是onFling。

I'm not really sure why, but as soon as I put Overrides for ALL of the possible gestures in a SimpleOnGestureListener it started working. Apparantly it needed them all in there, not just onFling.

这篇关于安卓:GestureDetector不会赶上手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆