New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: External control of wrapping criteria #32
Comments
Hi, Thanks for your suggestion. Because you don't have to nest ViewGroups to do so in the grid example above. E.g. If you want make the first row having two cells, the second row having three cells and the third row having four cells, you can write a XML like below (omitting the not relevant attributes). <com.google.android.flexbox.Flexbox
app:flexWrap="wrap">
<View app:layout_flexBasisPercent="50%"
app:layout_flexGrow="1">
<View app:layout_flexBasisPercent="50%"
app:layout_flexGrow="1">
<View app:layout_flexBasisPercent="30%"
app:layout_flexGrow="1">
<View app:layout_flexBasisPercent="30%"
app:layout_flexGrow="1">
<View app:layout_flexBasisPercent="30%"
app:layout_flexGrow="1">
<View app:layout_flexBasisPercent="25%"
app:layout_flexGrow="1">
<View app:layout_flexBasisPercent="25%"
app:layout_flexGrow="1">
<View app:layout_flexBasisPercent="25%"
app:layout_flexGrow="1">
<View app:layout_flexBasisPercent="25%"
app:layout_flexGrow="1">
</com.google.android.flexbox.Flexbox> I think the layout above gives you the same result as you HTML as you pasted. Instead if you want to give each flex item a fixed initial width and want to make the FlexboxLayout grow (have a new flex line) when a flex item doesn't fit in the current flex line, you can also do so like the example in the wiki Having that flexibility is one of the big advantages of the Flexbox and I think adding a explicit flag to indicate from which flex item the wrap should happen loses that flexibility. How do you think? |
But that only works if you manually specify the percentages and can already be achieve efficiently on Android using |
Ok, I understand controlling when wrap occurs is equivalent to having fixed number of items in each grid row. |
That would work, but would further compilicate an API which already isn't that intuitive for Android devs (alignItems vs. alignContent). That's the primary reason I'm suggesting what I am - increased control over internal behaviour via simple, understandable API additions. However, any additions to the functionality which would facilitate flattened layouts for tabular data would be greatly welcomed by me ;-) |
Sorry for the long delay. I'm going to add this request to the queue of the upcoming implementation plan. Thanks. |
Fixed by #60 |
While it would certainly diverge from the CSS flexbox model upon which this library is based, there are some inherent inefficiencies for Android because of differences in cost in nesting
ViewGroup
s in Android compared to nesting<div>
elements in HTML.For tabular data, the following is simple and efficient in HTML:
And CSS flexbox can easily be applied to this. However for Android This would need to be done with a parent
ViewGroup
representinggrid
, containing an number for childgrid_row
ViewGroup
s, each containing a collection ofView
s representing the individual the individual cells. Such a hierarchy is somewhat inefficient both in terms of layout inflation, and during measurement and layout.A couple of simple additions to
FlexboxLayout
could make it easy to flatten such layouts by removing the individual rows -FlexboxLayout
manages a collection ofFlexLine
objects which get calculated during measurement - and this is much more efficient that having child ViewGroups representing individual rows. If it were possible to have some optional attributes which could control when we should wrap to a newFlexLine
then the usefulness of FlexboxLayout would increase dramatically, I think. Specifically we could have aflexLineItems
integer which would cause a wrap whenever the currentFlexLine
contains the specified number of items. In addition aLayoutParams.wrapAfter
boolean (default tofalse
) could be used to force a wrap after the current childView
.As I said, I appreciate that this is a deviation from the CSS flexbox model, but feel that it could be a really useful addition on Android.
The text was updated successfully, but these errors were encountered: