check if an android scrollview can scroll

johanvs picture johanvs · Jul 28, 2014 · Viewed 15.4k times · Source

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.

I don't see in the reference a method who can give this information. Maybe is it possible to do something with the size of the linearlayout inside the scrollview?

Answer

johanvs picture johanvs · Jul 28, 2014

I used the following code inspired by https://stackoverflow.com/a/18574328/3439686 and it works!

ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView);
int childHeight = ((LinearLayout)findViewById(R.id.scrollContent)).getHeight();
boolean isScrollable = scrollView.getHeight() < childHeight + scrollView.getPaddingTop() + scrollView.getPaddingBottom();