N
N
nkizza2014-10-13 21:08:13
Android
nkizza, 2014-10-13 21:08:13

How to recognize zoom gesture and other gestures on the same View in Android?

I have a TextView wrapped in a ScrollView. I want to hang several gesture detectors on this TextView in order to recognize different gestures on this View. In particular, I need ScaleGestureDetector (recognizes the zoom gesture) and GestureDetector (recognizes tap, double tap, long press and others). Listener to both detectors is done, I hang it on View OnTouchListener:

tw.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View view, MotionEvent motionEvent) {
        if (!gestureDetector.onTouchEvent(motionEvent)) {
            scaleGestureDetector.onTouchEvent(motionEvent);
        };
        return true;
    }
});

Gestures are not recognized (or rather, not a single procedure in the Listener works, despite the fact that the listeners for the detectors are assigned according to the instructions). If you hang the detectors separately, then everything works:
tw.setOnTouchListener(new OnTouchListener() {
    public boolean onTouch(View view, MotionEvent motionEvent) {
        scaleGestureDetector.onTouchEvent(motionEvent);
        return false;
    }
});

Please help with an example of how this is done? Do I need to use several detectors in this situation, or have I missed something?
Thanks a lot.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Skrylnikov, 2014-10-13
@nkizza

I would try to read here habrahabr.ru/post/120931

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question