1

I need to detect swipe direction. In my code I can detect the direction, but it comes like, if I swipe right top right or left-top like that coming. same for the left, my requirement is without lifting a finger if I swipe left it should come only left, likewise all the directions. Can anyone help me out. Thanks in advance!

Here is my code

@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;
}
Mohammad Azhar
  • 71
  • 1
  • 10

2 Answers2

0

There are many gestures library and methods below is one I think will be use full

https://android-arsenal.com/details/1/3323

list of swipe gestures and other useful gestures are below

https://android-arsenal.com/tag/147

krishank Tripathi
  • 616
  • 1
  • 7
  • 23
0

A "touch gesture" occurs when a user places one or more fingers on the touch screen, and your application interprets that pattern of touches as a particular gesture.

For more information refer these links:-

1. https://developer.android.com/reference/android/view/GestureDetector.OnGestureListener.html

2. http://en.proft.me/2017/06/25/detecting-gestures-android-gesturedetector/

Ankita
  • 1,129
  • 1
  • 8
  • 15