Android – onscroll gesture detector

I want to implement onscroll when a scrolling event occurs. But I don't understand how to use the parameters received by onscroll (motionevent E1, motionevent E2, float distancex, float distancey) to detect scrolling from bottom to top

I'd love to get some guidance on how to implement it or some examples

resolvent:

You should be able to use the distancey parameter to determine whether the view scrolls up or down. Distancey represents the distance along the Y axis since onscroll() was last called. If the value of distancey is greater than zero, the view has scrolled from the lower position on the Y axis to the higher position on the Y axis

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    if (distanceY > 0) {
        // Scrolled upward
        if (e2.getAction() = MotionEvent.ACTION_UP) {
            // The pointer has gone up, ending the gesture
        }
    }
    return false;
}

Note: I haven't tested motionevent.action yet_ Whether up can solve the problem that needs to be checked at the end of scrolling, but it seems very practical in theory. Also, note that technically, if the operation of motionevent is set to motionevent.action_ Cancel, the gesture may also end

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>