Android 如何使动态创建的视图垂直排列?

Android 如何使动态创建的视图垂直排列?,android,android-linearlayout,Android,Android Linearlayout,我有一条直线。按钮“go”添加了XML: <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below=

我有一条直线。按钮“go”添加了XML:

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView21"
    android:layout_marginTop="10dp"
    android:background="#0099FF"
    android:text="go"
    android:textColor="#FFFFFF" />
当前元素水平排列:


如何使它们垂直排列?

您是否尝试将
orientation=“vertical”
添加到您的线性布局中?

例如


您是否尝试将
orientation=“vertical”
添加到线性布局中?

例如



Nope,我会试试看,你在线性布局的xml文件中设置了“方向”=垂直吗?是的,android:orientation=“vertical”在workedNope,我会试试看,你在线性布局的xml文件中设置了“方向”=垂直吗?是的,android:orientation=“vertical”在workedtry中只在注释部分放置类似答案的排序注释。我不同意,大多数人向下滚动到“答案”部分,以找到他们遇到的问题的解决方案。如果答案在评论中,他们不会看到,你不这样认为吗?试着把这类评论像答案一样只放在评论部分。我不同意,大多数人向下滚动到答案部分,以找到解决问题的方法。如果答案在评论中,他们不会看到,你不觉得吗?
for (final String str : strs) {
    CheckBox cb = new CheckBox(getApplicationContext());
    cb.setText(str);
    cb.setTextColor(Color.BLACK);
    thisll.addView(cb);
}
<LinearLayout
    android:layout_height="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <!-- The things you want aligned vertically go here -->
</LinearLayout>