Abdennacer Lachiheb
Abdennacer Lachiheb

Reputation: 4888

Android LinearLayout fill with buttons

I want to fill the LinearLayout with buttons.

The way I want it, is by filling the top of the screen first until the end of the line then if there is no space left, go to the next line and so on, like in the below picture.

enter image description here

I tried this code but it fill the screen vertically

    LinearLayout layout = (LinearLayout) findViewById(R.id.linear_layout_tags);
    //layout.setOrientation(LinearLayout.VERTICAL);
    layout.setGravity(Gravity.FILL);
    Button bt1 = new Button(this);
    bt1.setText("A Button");
    bt1.setLayoutParams(new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT));
    layout.addView(bt1);

Any help or suggestions would be appreciated.

Upvotes: 0

Views: 142

Answers (3)

Eugen Pechanec
Eugen Pechanec

Reputation: 38223

Or you're looking for FlowLayout for Android. Some implementations are here.

https://github.com/ApmeM/android-flowlayout

https://github.com/blazsolar/FlowLayout

Upvotes: 1

Ravi
Ravi

Reputation: 35539

Are you looking for one of this?

MultiTextTagView
TokenAutoComplete
Android Chips
AndroidTagView
Chips Android

Upvotes: 1

pawegio
pawegio

Reputation: 1732

What you are looking for is a FlexboxLayout.

Upvotes: 1

Related Questions