I have one ScrollView
with one LinearLayout
with TextView
s. I want to detect when ScrollView
is scrolling up or down to hide/show ActionBar
.
Do you know if it is possible to know if an Android Widget ScrollView can scroll? If it has enough space it doesn't need to scroll, but as soon as a dimension exceeds a maximum value the widget can scroll.
You can use Scroll listener to detect scroll up or down changes in RecyclerView . RecycleView invokes the onScrollStateChanged() method before onScrolled() method. The onScrollStateChanged() method provides you the RecycleView's status: SCROLL_STATE_IDLE : No scrolling.
ScrollView is used to put different or same child views or layouts and the all can be scrolled. ListView is used to put same child view or layout as multiple items. All these items are also scrollable. Simply ScrollView is for both homogeneous and heterogeneous collection.
you need to create a class that extends ScrollView
public class ExampleScrollView extends ScrollView
and then Override onScrollChanged
that gives you the old and new scroll positions and from there you can detect which direction
protected void onScrollChanged(int l, int t, int oldl, int oldt)
check this out
scrollView.setOnTouchListener(new View.OnTouchListener() {
float y0 = 0;
float y1 = 0;
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_MOVE) {
y0 = motionEvent.getY();
if (y1 - y0 > 0) {
Log.i("Y", "+");
AnimateFloat(true);
} else if (y1 - y0 < 0) {
Log.d("Y", "-");
AnimateFloat(false);
}
y1 = motionEvent.getY();
}
return false;
}
});
I think I am little bit late to answer this but here is my answer
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
float y = 0;
@Override
public void onScrollChanged() {
if (scrollView.getScrollY() > y) {
Log.v("Message", "Scrolls Down");
} else {
Log.v("Message", "Scrolls Up");
}
y = scrollView.getScrollY();
}
});
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