ScaleGestureDetector does not detect gesture

I connected the ScaleGestureDetector to OnTouchListener as described in the Android documentation. For some reason, the ScaleGestureDetector does not always detect the end of a hard clip. This occurs mainly with compression from large to small.

The effect is that after I released both fingers, the detector does not fire the gesture end event. If I touch the screen with one of them, he still thinks that I will continue a large-scale gesture (keeps shooting at Scale events). I have to make another gesture to make the detector catch fire.

I added the logs to OnTouchListener, and when the scale gesture gets stuck, I still get motion events when using one finger, and event.getPointerCount () is 1.

I made sure that I have no other listeners. The view that onTouchListener has is not the only view on the screen, but this effect also occurs when I am very careful to start and finish the gesture inside this one view.

Is there a way to improve end detection?

Or if I have a way to manually set the ScaleGestureDetector to run onScaleEnd and change it scaleGestureDetector.isInProgress()to false?

+3
source share
2 answers

I came up with a solution after applying the above fix. My application uses both ScaleGestureDetector, and regular GestureDetector, so I implemented in my method onScroll(from GestureDetector):

if (m_dualFingerGestureDetector.isInProgress() && (evt1.getPointerCount() == 2 || evt2.getPointerCount == 2)
{
    return false;
}
...

My variables are as follows:

m_dualFingerGestureDetector ScaleGestureDetector
evt1 evt2 MotionEvent . , :

if (m_dualFingerGestureDetector.isInProgress() && evt.getPointerCount() == 2)
{
    return false;
}
...

. .

+4

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


All Articles