2

プログラムでGestureDetectorsを使用する必要があります。1つは美しく機能し、もう1つは機能しません。私が知る限り、どちらも同じように実装されています。

動作していないものを実装するためのコードは次のとおりです。

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を定義するこのブロックがあります

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")を出力する必要がありますが、出力されません。私が知っているのは、最初に示したブロックから「Excuse Gesture Return」「false」をトレースするため、ある種のタッチイベントが発生したことを登録することだけです。なぜそれがフリングを登録しないのかについて何か考えはありますか?

4

2 に答える 2

4

理由はよくわかりませんが、SimpleOnGestureListenerにすべての可能なジェスチャのオーバーライドを設定するとすぐに機能し始めました。明らかに、onFlingだけでなく、そこにすべてが必要でした。

于 2010-10-26T22:20:29.283 に答える
1

これはおそらくあなたがしたことも必要ではなく、あなたのためにそれを機能させるのはあなたの活動が次のようにonTouchEventsomtehingをオーバーライドすることです:

@Override
public boolean onTouchEvent(MotionEvent event) {
  if (myGestureDetector.onTouchEvent(event)) {
    return true;
  } else {
    return false;
  }
}

私はこの素晴らしいサイトで答えを見つけました。

于 2010-12-01T08:10:01.647 に答える