0
我想先从刷卡向左或向右的手势在活动的活动,用下面的代码:禁用上下一扔滑动手势与GestureDetectorCompat
gestureDetector = new GestureDetectorCompat(this, new GestureDetector.SimpleOnGestureListener(){
private static final int SWIPE_THRESHOLD = 50;
private static final int SWIPE_VELOCITY_THRESHOLD = 0;
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {
//user will move forward through messages on fling up or left
boolean forward = false;
//user will move backward through messages on fling down or right
boolean backward = false;
//calculate the change in X position within the fling gesture
float horizontalDiff = event2.getX() - event1.getX();
//calculate the change in Y position within the fling gesture
float verticalDiff = event2.getY() - event1.getY();
float absHDiff = Math.abs(horizontalDiff);
float absVDiff = Math.abs(verticalDiff);
float absVelocityX = Math.abs(velocityX);
float absVelocityY = Math.abs(velocityY);
if(absHDiff > absVDiff && absHDiff > SWIPE_THRESHOLD && absVelocityX > SWIPE_VELOCITY_THRESHOLD){
//move forward or backward
if(horizontalDiff>0) backward=true;
else forward=true;
}
else if(absVDiff > SWIPE_THRESHOLD && absVelocityY > SWIPE_VELOCITY_THRESHOLD){
if(verticalDiff>0) backward=true;
else forward=true;
}
//user is cycling forward through messages
if(forward){
//check current message is not at end of array, increment or set back to start
swipeTo(SWIPE_LEFT);
}
//user is cycling backwards through messages
else if(backward){
//check that current message is not at start of array, decrement or set to last message
swipeTo(SWIPE_RIGHT);
}
//return super.onFling(event1, event2, velocityX, velocityY);
return true;
}
});
如何禁用从动作当滑动垂直时(从上到下或从下往上)时,会采取什么措施?
SWIPE_LEFT和SWIPE_RIGHT只是分别具有值1和2的类成员常量。
在此先感谢。
谢谢@jaibatrik,但多少“太高”? – Shareb
使用'android.util.Log'打印垂直绝对速度值。尝试并最终确定适合您的价值。 – jaibatrik