Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Total height of ScrollView

I have a custom ScrollView (extended android.widget.ScrollView) which I use in my layout. I want to measure the total height of the contents of this scrollview. getHeight() and getMeasuredHeight() don't give me correct values (too high numbers).

Background information: I want to determine how far the user has scrolled. I use onScrollChanged to get the X value, but I need to know a percentage so I'll need the total scrollbar height.

Thanks a lot! Erik

like image 897
Erik Avatar asked Aug 31 '10 13:08

Erik


People also ask

How do I get ScrollView height in react native?

Get the height of the contents within the ScrollView ("contentHeight") Use the ScrollView's "onScroll" event to get the scroll offset. Use it to update the scrollOffset animation. Create a ScrollBar component based on the scrollOffset animation value, containerHeight, and contentHeight.


1 Answers

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

int totalHeight = scrollView.getChildAt(0).getHeight(); 
like image 126
satur9nine Avatar answered Oct 02 '22 17:10

satur9nine