Etienne Lawlor
Etienne Lawlor

Reputation: 6687

Set maxHeight for a ViewGroup

A ViewGroup has a property called minHeight which allows you to set the minimum height of the ViewGroup.

http://developer.android.com/reference/android/view/View.html#attr_android:minHeight

There is no property called maxHeight. So how exactly can you set the maxHeight of a ViewGroup? It seems that you must do something in the ViewGroup's overridden methods and not in XML. I attempted to do something like this in onMeasure() but had no luck. Does anyone have any ideas?

Update

Specifically, I want to set height="wrap_content" while also setting a maxHeight of a FlowLayout

But the views within the FlowLayout are not being displayed.

Upvotes: 0

Views: 1167

Answers (1)

Blackbelt
Blackbelt

Reputation: 157437

you have to override onMeasure() and call setMeasuredDimension. For instance

    setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), mMaxHeight);

where mMaxHeight can be a fixed value, or you can loop on the ViewGroup's children, measure them, and calculate this value

Upvotes: 2

Related Questions