0

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.

Community
  • 1
  • 1
Etienne Lawlor
  • 6,817
  • 18
  • 77
  • 89

1 Answers1

1

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

Blackbelt
  • 156,034
  • 29
  • 297
  • 305