Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know that the scrollview is already scrolled to the bottom?

I have a scrollview and I only want an event to happen if it's already scrolled to the bottom but I can't find a way to check if the scrollview is at the bottom.

I have solved it for the opposite; only allow the event to happen if it's already scrolled to the top:

ScrollView sv = (ScrollView) findViewById(R.id.Scroll);
    if(sv.getScrollY() == 0) {
        //do something
    }
    else {
        //do nothing
    }
like image 215
sanna Avatar asked May 19 '10 10:05

sanna


1 Answers

I found a way to make it work. I needed to check the measured height of the child to the ScrollView, in this case a LinearLayout. I use the <= because it also should do something when scrolling isn't necessary. I.e. when the LinearLayout is not as high as the ScrollView. In those cases getScrollY is always 0.

ScrollView scrollView = (ScrollView) findViewById(R.id.ScrollView);
    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.LinearLayout);
    if(linearLayout.getMeasuredHeight() <= scrollView.getScrollY() +
           scrollView.getHeight()) {
        //do something
    }
    else {
        //do nothing
    }
like image 136
sanna Avatar answered Oct 07 '22 18:10

sanna