当用户在我的屏幕的网格视图上滑动时,我正在尝试实现某些功能。我尝试使用SimpleOnGestureListener,如下所示:
class MyGestureDetector extends SimpleOnGestureListener {
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) {
Log.w(null,"Right to Left swipe detected");
return true;
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Log.w(null,"Left to Right swipe detected");
return true;
}
} catch (Exception e) {
// nothing
}
return false;
}
}
但是我无法检测到运动事件。我尝试调试,并看到事件e1传递为null。有人可以帮忙吗?