flexbox-layout icon indicating copy to clipboard operation
flexbox-layout copied to clipboard

View's minHeight not respected

Open golddove opened this issue 5 years ago • 3 comments

  • [x] 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);

golddove avatar Nov 17 '20 02:11 golddove

This does still appear to be an issue in v3

phazei avatar May 05 '23 01:05 phazei

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

phazei avatar May 07 '23 23:05 phazei

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

tapczan1337 avatar Dec 27 '23 11:12 tapczan1337