I want to implement onScroll, when scroll event occurs. However I don't understand how can I detect the scroll from bottom up with the parameters that I receive with onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY).
I would be happy to get some guidelines how to implement it or some examples.
You should be able to use the distanceY
parameter to determine whether the view was scrolled up or down. distanceY
represents the distance along the Y axis that has been scrolled since the last call to onScroll()
. If the value of distanceY
is greater than zero, the view has been scrolled from a lower position on the Y axis to a 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 have not tested if the MotionEvent.ACTION_UP
will solve your need to check when scrolling has ended, but it seems practical in theory. Also note that technically the gesture could also end if the MotionEvent
's action is set to MotionEvent.ACTION_CANCEL
.
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