我的问题是对角线的动作。当我做对角线时,我希望它被识别为向上或向下运动。但我的代码认为区域运动是左或右。
我该怎么做?我想问题必须在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;
}