I want to detect the end of scroll event of a scrollView. first,i implement the OnCrollChange method and i try to listen some values if they can help me to know the end of scroll. Thank to help me.
scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener(){
@Override
public void onScrollChange(View view, int i, int i1, int i2, int i3){
Toast.makeText(getApplicationContext(),"in SCroll ------->"+i+" "+i1+" "+i2+" "+i3,Toast.LENGTH_SHORT).show();
shadowView.setBackgroundResource(R.drawable.shadow);
if ((i3==0)){
Toast.makeText(getApplicationContext()," equality ----------------------> ",Toast.LENGTH_SHORT).show();
shadowView.setBackgroundResource(R.drawable.trans);
}
else {
// Toast.makeText(getApplicationContext()," NO ----------------------> ",Toast.LENGTH_SHORT).show();
}
}
});
This will help
scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
if (scrollView != null) {
if (scrollView.getChildAt(0).getBottom() <= (scrollView.getHeight() + scrollView.getScrollY())) {
//scroll view is at bottom
} else {
//scroll view is not at bottom
}
}
}
});
Modify your onScrollChanged
method as below
@Override
public void onScrollChanged(View view, int i, int i1, int i2, int i3){
View view = (View) getChildAt(getChildCount()-1);
int delta = (view.getBottom()-(getHeight()+getScrollY()));
if(delta == 0){
// You have reached bottom of the scroll view
}
}
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