flexbox-layout
flexbox-layout copied to clipboard
setFlexBasisPercent does not take a percentage
The method FlexboxLayout.LayoutParams.setFlexBasisPercent
is implemented incorrectly. It multiplies its argument by 100, and it should not.
If it is named set...Percent
, it must take a percentage.
If it does not take a percentage, naming it setFlexBasisPercent
is misleading.
I don't see where it multiplies its argument by 100. Can you provide more information?
https://github.com/google/flexbox-layout/blob/1.1.1/flexbox/src/main/java/com/google/android/flexbox/FlexboxLayout.java#L1793-L1796
You're right—it doesn't directly multiply the value by 100, but it does use the value in such a way that the result is too large by a factor of 100.
Here's an example:
https://github.com/google/flexbox-layout/blob/9db6bb19de8b75b2b61787142415e40766697006/flexbox/src/main/java/com/google/android/flexbox/FlexboxHelper.java#L450
This expression:
childMainSize = Math.round(mainSize * flexItem.getFlexBasisPercent());
treats the result of getFlexBasisPercent()
as a multiplier, not as a percentage. Setting the flex basis to 50% should make the child half the space If you set the percentage to 50, instead of representing a ratio of one-half, mainSize
will be multiplied by 50.
This is really a naming issue—this field is being used as a fraction rather than a percentage.
Agreed, this is confusing. Perhaps setFlexBasisRatio
would have been a better name.