Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pan Gesture Recognizer For Android?

I'm replicating my IOS App that heavily uses Pan Gesture Recognizer to Android and I couldn't find similar Gesture recognizer. Is there such thing?

any direction is appreciated thanks

like image 878
RollRoll Avatar asked Jul 03 '13 16:07

RollRoll


2 Answers

I think what you're looking for is GestureDetector. I'm not very familiar with iOS's Pan Gesture Recognizer, but I think it does't work exactly the same way in Android. See the developer guide topic Using Touch Gestures for info on how to use the class.

like image 117
Ted Hopp Avatar answered Sep 19 '22 11:09

Ted Hopp


Android comes out of the box with two classes that recognize gesture. One is GestureDetector and the other is ScaleGestureDetector.

Unlike, ios, the basic gesture detector framework is limited - you can't specify dependencies, do conflict resolution or configure them by specifying touch points etc like you can in ios's UiGestureRecognizer class.

To answer your question, pan can be detected using the GestureDetector. Here is a snippet:

PanGestureListener listener = new PanGestureListener();
GestureDetector detector = new GestureDetector(context, listener);

class PanGestureListener extends GestureDetector.SimpleOnGestureListener {

    @Override
    public boolean onScroll(MotionEvent e1, 
                            MotionEvent e2, 
                            float distanceX, 
                            float distanceY) {

        //YOUR "pan handler"
        return true;
    }

}

Now in your onTouch method just forward all the calls to detector.onTouch like this:

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        detector.onTouchEvent(event);
        return true;
    }
like image 27
numan salati Avatar answered Sep 20 '22 11:09

numan salati