Reputation: 4393
I want to put fixed-dimension buttons centred in a layout so that they automatically go to the next line when they are too many. But I know that this behaviour doesn't work with LinearLayout.
Do you have an idea on how I can proceed?
Here is the behaviour that I would like:
Upvotes: 9
Views: 3704
Reputation: 1470
The Flexbox library from Google does exactly this:
Add the dependency to app/build.gradle:
dependencies {
implementation 'com.google.android:flexbox:2.0.1'
}
Usage of the layout:
<com.google.android.flexbox.FlexboxLayout
app:flexWrap="wrap">
<View/>
<View/>
<View/>
<View/>
</com.google.android.flexbox.FlexboxLayout>
Upvotes: 9
Reputation: 4393
I finally proceeded dynamically : I created a LinearLayout for each line, and calculated the width taken by the rectangles compared to the global layout width to calculate the number of lines needed and to put each rectangle in the good line.
Upvotes: -1