views:

77

answers:

2

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
    }
A: 

If scrollView.getHeight() == scrollView.getScrollY + screensize, then it is scrolled to bottom.

Karan
Thank you but when the scroll is at bottom getScrollY = 349getBottom = 430getMeasuredHeight = 430getHeight = 430The last three are the same no matter how far down I have scrolled.The only thing that varies is getScrollY.What is this screensize you mention? Did I missinteroperate it? It should be 81 in this case and I can't think of anything that is that.
sanna
A: 

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
    }
sanna