Android: ScrollView overall height

I have my own ScrollView (advanced android.widget.ScrollView), which I use in my layout. I want to measure the overall height of the contents of this scroll. getHeight () and getMeasuredHeight () do not give me the correct values ​​(numbers are too high).

Background information: I want to determine how far the user scrolls. I use onScrollChanged to get the X value, but I need to know the percentage, so I need the overall scrollbar height.

Thank you so much! Erik

+27
android scroll scrollview
Aug 31 '10 at 13:05
source share
2 answers

ScrollView always has 1 child. All you have to do is get the height of the child to determine the total height:

int totalHeight = scrollView.getChildAt(0).getHeight(); 
+70
Feb 14 2018-11-11T00:
source share

See ScrollView source. Unfortunately, this method is private, but you can copy it into your own code. Please note that other answers do not include registration

 private int getScrollRange() { int scrollRange = 0; if (getChildCount() > 0) { View child = getChildAt(0); scrollRange = Math.max(0, child.getHeight() - (getHeight() - mPaddingBottom - mPaddingTop)); } return scrollRange; } 
0
Oct 10 '17 at 11:45
source share



All Articles