Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android GestureDetector onScroll unexpected behavior

I have SimpleGestureDetectorListener and implemented onScroll as follows:

    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,     float distanceY)
    {
        Log.i("MOVE_LARGE", "e1.getY=" + e1.getY()+" "+"e2.getY="+e2.getY());
        Log.i("MOVE_SMALL", "distanceY=" + distanceY);
        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams)      fragmentContainer.getLayoutParams();
        int nextMargin = params.topMargin - (int) distanceY;
        if (Math.abs(distanceY )> MOVE_TRESHOLD)
        {
            setContainerMargin(nextMargin);
        }
        return true;
    }

As you might guess, i move some view. So when i move it at some point when I stop my finger on screen, view starts jumping back and forth.

I have logged events and have such picture:

   03-09 10:57:02.874: I/MOVE_EVENT(27478): 2
   03-09 10:57:02.875: I/MOVE_LARGE(27478): e1.getY=24.892685 e2.getY=261.41266
   03-09 10:57:02.875: I/MOVE_SMALL(27478): distanceY=23.0
   03-09 10:57:02.891: I/MOVE_EVENT(27478): 2
   03-09 10:57:02.892: I/MOVE_LARGE(27478): e1.getY=24.892685 e2.getY=284.41266
   03-09 10:57:02.892: I/MOVE_SMALL(27478): distanceY=-23.0
   03-09 10:57:02.908: I/MOVE_EVENT(27478): 2
   03-09 10:57:02.908: I/MOVE_LARGE(27478): e1.getY=24.892685 e2.getY=261.41266
   03-09 10:57:02.908: I/MOVE_SMALL(27478): distanceY=23.0
   03-09 10:57:02.925: I/MOVE_EVENT(27478): 2
   03-09 10:57:02.925: I/MOVE_LARGE(27478): e1.getY=24.892685 e2.getY=284.41266
   03-09 10:57:02.925: I/MOVE_SMALL(27478): distanceY=-23.0
   03-09 10:57:02.941: I/MOVE_EVENT(27478): 2

And it keeps repeating if I don't move the finger. Treshold is not the problem, because distance varies widely (from 10 to 100). Event is 2==ACTION_MOVE.

What is the problem and how to work around it?

like image 819
Giorgi EgoTwin Khutsishvili Avatar asked Jun 18 '26 18:06

Giorgi EgoTwin Khutsishvili


1 Answers

Alright, the problem is that I was trying to move some view and I assigned touch listener (not intentionally) to view that was being moved. So that is what caused my "unexpected behavior".

like image 150
Giorgi EgoTwin Khutsishvili Avatar answered Jun 21 '26 11:06

Giorgi EgoTwin Khutsishvili



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!