Android LinearLayout填充按钮

时间:2016-10-12 09:44:08

标签: android android-layout

我想用按钮填充LinearLayout。

我想要它的方式是首先填充屏幕顶部直到行尾,然后如果没有剩余空间,转到下一行,依此类推,如下图所示。

enter image description here

我尝试了这段代码,但它垂直填满了屏幕

    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);

任何帮助或建议都将不胜感激。

3 个答案:

答案 0 :(得分:1)

您要找的是FlexboxLayout

答案 1 :(得分:1)

答案 2 :(得分:1)

或者您正在寻找适用于Android的FlowLayout。一些实现在这里。

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

https://github.com/blazsolar/FlowLayout