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
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.
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; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With