スタックオーバーフロー コミュニティの皆様、こんにちは。
SimpleOnGestureListener に非常に奇妙な問題があります。
public class OnSwipeTouchListener implements View.OnTouchListener {
//constructor...
@SuppressWarnings("deprecation")
private final GestureDetector gestureDetector = new GestureDetector(new GestureListener());
public boolean onTouch(final View v, final MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
private final class GestureListener extends GestureDetector.SimpleOnGestureListener {
private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
float diffX = e2.getRawX() - e1.getRawX();
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (diffX > 0) {
onSwipeRight();
}
if(diffX < 0) {
onSwipeLeft();
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
return false;
}
}
public void onSwipeRight() {
Log.i("PPTREMOTE", "Swiped Right!");
main.previousSlide();
}
public void onSwipeLeft() {
Log.i("PPTREMOTE", "Swiped Left!");
main.nextSlide();
}
}
私の問題は非常に奇妙です。onFling は、左にスワイプしているときにのみ呼び出されます?!
テポレンタ