Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Put views in an Android layout with automatic line break

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:

enter image description here

like image 968
johanvs Avatar asked Apr 19 '14 09:04

johanvs


1 Answers

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>
like image 97
Ari Avatar answered Oct 12 '22 23:10

Ari