Here is what I would like my ScrollView to look like:
- The maximum size is defined with the layout_weight (so that other items below the ScrollView can be displayed properly)
- If the content is smaller than that maximum size, then it just behaves as with
layout_height="wrap_content"
Here is what I currently have:
<ScrollView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:measureAllChildren="true"
android:fillViewport="false"
>
I don’t think the measureAllChildren really does anything at all…
If I add android:layout_weight, the size will always be what I would like the maximum to be. Without it, it just extends more than it should…
I don’t mind extending the ScrollView class to change the behavior of onMeasure if I need to…?
PS: If that makes a differences, I am trying to get this working from Froyo onward.
I ended up writing my own class, extending ScrollView
Since you ask…here is the code. Probably not the cleanest but it does what I want.
Note that it expects the layout_weight to be set when the view is created and you should not set the weigthSum in the parent LinearLayout or you’ll get funny things (since the weight of this one changes from the original value to 0 depending on the size of the content of the ScrollView)
First, in the layout file, the view is declared like this:
Then the code for the widget: