user2150445 user2150445 - 4 months ago 36
Android Question

Android ScrollView set height for displayed content

I'm having a lot of trouble trying solve the issue of having a static height scrollable area within a layout. I have three long lists that need to be displayed on the same screen and it would be entirely impractical to display all of the entries sequentially because then if you want to skip a category you need to scroll past possibly hundreds of entries.

Assume I have a scroll view with a Linear Layout inside of it, I want this to take up say, 250dp height on the screen at max and be independently scrollable once populated with more entries than can fit in 250dp's space.

What I have now is:

<ScrollView
android:minWidth="25px"
android:minHeight="150px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/XXXXXXX"
android:scrollbars="vertical">
<LinearLayout
android:orientation="vertical"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/XXXXXX" />
</ScrollView>


When populated, the scrollview and linearlayout just stretch as long as they needs to to fit the content and displays all of it instead of having a "window" of 250dp/px (any measurment would be nice) with the content scrollable within it.

I'm new to the android platform, so perhaps the answer is obvious and I just didn't understand the language, but any help would be greatly appreciated!
Thank you

--- SOLVED:
Put a linearLayout outside of the ScrollView with the height.

Answer

What you need is a maxHeight. But since views do not support it, you have to use a workaround.

Check out this answer:

http://stackoverflow.com/a/13811461/770467

Comments