我需要检测滑动方向。在我的代码中,我可以检测到方向,但它就像是,如果我像这样向右上方或左上方滑动。左边也一样,我的要求是如果我向左滑动它应该只向左移动,就像所有方向一样。谁能帮我吗。提前致谢!
这是我的代码
@Override
public boolean onScroll(MotionEvent event1, MotionEvent event2, float distanceX, float distanceY) {
if (Math.abs(deltaX) > Math.abs(deltaY)) {
if (Math.abs(deltaX) > MIN_DISTANCE) {
if (deltaX > leftSidelastX) {
leftSidelastX = deltaX;
Log.d("", "Right to Left swipe performed");
} else {
leftSidelastX = deltaX;
Log.d("", "Left to Right swipe performed");
}
}
} else {
if (Math.abs(deltaY) > MIN_DISTANCE) {
if (deltaY > leftSidelastY) {
leftSidelastY = deltaY;
Log.d("", "Up to Down swipe performed");
} else {
leftSidelastY = deltaY;
Log.d("", "Down to Up swipe performed");
}
}
}
return true;
}