Take a look at the decision made here - Fling gesture detection on grid layout
This solution explains how to implement a simple gesture listener, and write left and right and right to left spaces. The corresponding code from the example is given in the GestureDetector onFling override method. In principle, if point 1 (e1) minus point 2 (e2) is greater than the specified minimum distance, then you know this from right to left. If point 2 (e2) minus point 1 (e1) was greater than the minimum travel distance, then it is left to the right.
// right to left swipe if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(SelectFilterActivity.this, "Left Swipe", Toast.LENGTH_SHORT).show(); } // left to right swipe else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { Toast.makeText(SelectFilterActivity.this, "Right Swipe", Toast.LENGTH_SHORT).show(); }
source share