views:

64

answers:

1

View's have a minHeight but somehow are lacking a maxHeight: http://goo.gl/qRyp

What I'm trying to achieve is having some items (views) filling up a ScrollView. When there are 1..3 items I want to display them directly. Meaning the ScrollView has the height of either 1, 2 or 3 items.

When there are 4 or more items I want the ScrollView to stop expanding (thus a maxHeight) and start providing scrolling.

However, there is unfortunately no way to set a maxHeight. So I probably have to set my ScrollView height programmatically to either WRAP_CONTENT when there are 1..3 items and set the height to 3*sizeOf(View) when there are 4 or more items.

Can anyone explain why there is no maxHeight provided, when there is already a minHeight?

(BTW: some views, like ImageView have a maxHeight implemented.)

+1  A: 

Have you tried using the layout_weight value? If you set one it to a value greater than 0, it will stretch that view into the remaining space available.

If you had multiple views that needed to be stretched, then the value will become a weight between them.

So if you had two views both set to a layout_weight value of 1, then they would both stretch to fill in the space but they would both stretch to an equal amount of space. If you set one of them to the value of 2, then it would stretch twice as much as the other view.

Some more info here listed under Linear Layout.

Bryan Denny