我的问题是对角线运动。当我做对角线时,我希望它被识别为向上或向下运动。但是我的代码将对角线运动识别为左或右。
我怎样才能做到这一点?我想问题一定出在 if 条件下,但我不明白。
这是我的 OnFling() 方法的代码:
@Override
public boolean onFling(MotionEvent event1, MotionEvent event2,
float velocityX, float velocityY) {
Log.d(DEBUG_TAG1, "onFling: " + event1.toString()+event2.toString());
if(event1.getX() - event2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
{
// movetoleft
Log.d(DEBUG_TAG3,"move left");
currentMove = 4;
Log.d(DEBUG_TAG3,"current move: " + currentMove);
return true;
}
else if (event2.getX() - event1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY)
{
// movetoright
Log.d(DEBUG_TAG3,"move right");
currentMove = 2;
Log.d(DEBUG_TAG3,"current move: " + currentMove);
return true;
}
if(event1.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY)
{
//moveUp
Log.d(DEBUG_TAG3,"move up");
currentMove = 1;
Log.d(DEBUG_TAG3,"current move: " + currentMove);
return true;
}
else if (event2.getY() - event1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY)
{
//moveDown
Log.d(DEBUG_TAG3,"move down");
currentMove = 3;
Log.d(DEBUG_TAG3,"current move: " + currentMove);
return true;
}
return true;
}