LinearLayout的子视图根据设备的宽度问题更改行

时间:2016-01-18 08:54:09

标签: android android-layout android-linearlayout textview

嗨朋友我正在使用LinearLayout 方向 horizontal以编程方式在其中填充TextView's

代码:

LinearLayout linearLayout = (LinearLayout)findViewById(R.id.layout1);
for (int i = 0; i < 20; i++) {
    TextView textView = new TextView(this);
    textView.setText("Hello " + i);
    linearLayout.addView(textView, i);
}

现在,我在屏幕上看起来非常奇怪:

enter image description here

我想要这种观点:

enter image description here

LinearLayout内的观点应根据设备宽度更改 。任何人都有任何想法,请帮助。

1 个答案:

答案 0 :(得分:0)

使用setNumColumns()将文本视图添加到网格布局。