View's minHeight not respected
golddove opened this issue · comments
- I have searched existing issues and confirmed this is not a duplicate
Issues and steps to reproduce
Create any viewgroup (for example, a LinearLayout), and place a FlexboxLayout inside it.
Set the FlexboxLayout's height to WRAP_CONTENT
. Assign a large min height (either using setMinimumHeight
or android:minHeight
inherited from View
) to the FlexboxLayout.
Notice how the FlexboxLayout height does not expand to the min height.
(There is an unresolved, but closed duplicate here: #536)
Expected behavior
The flexbox should take up at least minHeight, even if the flex items don't need that much height.
Version of the flexbox library
2.0.1
Link to code
flexboxLayout.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
flexboxLayout.setMinimumHeight(1000);
viewGroup.addView(flexboxLayout);
This does still appear to be an issue in v3
Here's a kind of hacky work around, works pretty well for my uses at least if the view is being extended:
init {
setupView()
paddingMod = listOf(paddingLeft, paddingTop, paddingRight, paddingBottom)
}
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
val minHeight = minimumHeight
//once the heights been adjusted, it will cycle back and forth each time this is called, so add 1 px leeway
if (measuredHeight < minHeight + 1) {
val extraPadding = minHeight - measuredHeight
if (extraPadding > 0) {
setPadding(paddingMod[0], paddingMod[1] + extraPadding, paddingMod[2], paddingMod[3])
}
} else {
setPadding(paddingMod[0], paddingMod[1], paddingMod[2], paddingMod[3])
}
}
Got around it with this simple code:
override fun onMeasure( widthMeasureSpec: Int, heightMeasureSpec: Int) {j
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
val minHeight = 50
if (measuredHeight < minHeight) {
setMeasuredDimension(measuredWidth, minHeight)
}
}