Hey just wanted to identify whether a scrollview is scrolling up or down in android .Wanted to do different actions while scrolling up and scrolling down.
Any idea is appreciated, thanks
When the page scroll happens, compare the previous scrollY value with the current scrollY . If the current value is greater than the old value, then the scroll direction is downwards. Otherwise, the scroll direction is upwards. Update the current scroll position to the variable.
Pressing page up scrolls up one page or gets you to the top of the page. Pressing page down scrolls down one page at a time or gets you to the bottom of the page. Some people may also refer to the page up and page down keys as the scroll keys, not to be confused with the scroll lock key.
android:fillViewport. Defines whether the scrollview should stretch its content to fill the viewport.
NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.
Try this: Extends Scrollview and override onTouchEvent method
private float mTouchPosition;
private float mReleasePosition;
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mTouchPosition = event.getY();
}
if (event.getAction() == MotionEvent.ACTION_UP) {
mReleasePosition = event.getY();
if (mTouchPosition - mReleasePosition > 0) {
// user scroll down
} else {
//user scroll up
}
}
return super.onTouchEvent(event);
}
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