Android Gesture, which is used on the start screen

Which Android Api is used to scroll left or right on the Android start screen?

+3
source share
3 answers

The easiest way is to detect the "Fling" gesture. The Android API has a built-in detector for basic gestures such as toss, scroll, long press, double tap, zoom, etc.

The documentation is available at http://developer.android.com/reference/android/view/GestureDetector.html .

What you do is create an instance of GestureDetector, override the onTouchEvent method for the view that you are interested in detecting gestures, and pass the MotionEvent to the GestureDetector.

OnGestureListener ( SimpleOnGestureListener) GestureDetector .

:

class MyView extends View
{
    GestureDetector mGestureDetect;

    public MyView(Context context)
    {
        super(context);
        mGestureDetect = new GestureDetector(new SimpleOnGestureListener()
        {

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) 
        {
        //check if the fling was in the direction you were interested in
        if(e1.getX() - e2.getX() > 0)
        {
        //Do something here
        }
        //fast enough?
        if(velocityX > 50)
        {
        //etc etc
        }

        return true;
        }
        }
    }

    public boolean onTouchEvent(MotionEvent ev)
    {
        mGestureDetector.onTocuhEvent(ev);
        return true;
    }
}
+5

GestureLibraries . .

I have not used this myself, so I cannot give you more information, but they can also be useful:

Android MotionEvent

Android - basic gesture detection

+1
source

Source: https://habr.com/ru/post/1753356/


All Articles