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

Measure flexBasisPercent when in a FlexBoxLayout using padding or dividerDrawable

Open chenfei0928 opened this issue 6 years ago • 1 comments

Issues and steps to reproduce

When I used padding or dividerDrawable on FlexBoxLayout, I used the flexBasisPercent property on the child view. The width of its child views will not meet my expectations: (parentViewGroupSize-padding-dividerDrawableSize*numberOfShownDividerDrawable) * flexBasisPercent Its actual width calculation becomes: the parent viewGroup size * flexBasisPercent, which caused me to set the flexBasisPercent of 0.333 for each child view, it will not display three per line, but two or even one will wrap.

Expected behavior

flexBasisPercent should consider the maximum displayable width of all child views when calculating, not just the width of the parent view, because it contains padding and dividerDrawable.

Version of the flexbox library

2.0.0

Link to code

<com.google.android.flexbox.FlexboxLayout
    android:layout_width="100dp"
    android:layout_height="wrap_content"
    android:padding="30dp"
    app:flexWrap="wrap">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_flexBasisPercent="0.33f"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_flexBasisPercent="0.33f"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_flexBasisPercent="0.33f"/>
</com.google.android.flexbox.FlexboxLayout>

or Measurement of childMainSize in the calculateFlexLines method in the FlexboxHelper file: childMainSize = Math.round(mainSize * flexItem.getFlexBasisPercent());

chenfei0928 avatar Dec 16 '19 05:12 chenfei0928

still not fixed, is there an easy workaround for this other than calculating the child size in the adapter?

I am currently calculating the percentage of width the padding takes and dividing the children between the remaining percentage 🤷🏻‍♂️

MarsVard avatar Sep 18 '24 13:09 MarsVard