我正在使用 Gesture Listner 来实现滑动屏幕导航。但是我需要多次滑动才能导航到下一个或上一个屏幕,这不太舒服。速度、偏离路径和最小距离的正确值是多少。
请在下面找到我的代码:
private static final int SWIPE_MIN_DISTANCE = 50;
private static final int SWIPE_MAX_OFF_PATH = 300;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
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) {
viewFlipper.setInAnimation(slideLeftIn);
viewFlipper.setOutAnimation(slideLeftOut);
viewFlipper.showNext();
configDisplay();
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
viewFlipper.setInAnimation(slideRightIn);
viewFlipper.setOutAnimation(slideRightOut);
viewFlipper.showPrevious();
configDisplay();
}
} catch (Exception e) {
// nothing
}
return false;
}
}