Hello stackoverflow社区,
我的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?
theporenta