google / flexbox-layout

Flexbox for Android
Apache License 2.0
18.24k stars 1.79k forks source link

View's minHeight not respected #562

Open golddove opened 3 years ago

golddove commented 3 years ago

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);
phazei commented 1 year ago

This does still appear to be an issue in v3

phazei commented 1 year ago

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])
        }
    }
tapczan1337 commented 8 months ago

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)
        }
    }