linearlayout怎么换行
时间: 2023-09-13 17:07:48 浏览: 42
在 LinearLayout 中,可以使用 `android:orientation` 属性来指定布局方向,可选值为 "horizontal" 和 "vertical",分别代表水平和竖直方向。当布局方向为 "horizontal" 时,子 View 会水平排列,当空间不足时会自动换行。如果你希望子 View 在竖直方向上排列,并且需要自动换行,可以将布局方向设置为 "vertical"。例如:
```
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, World!" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a long text that should wrap to the next line." />
</LinearLayout>
```
在上面的例子中,两个 TextView 会竖直排列,并且第二个 TextView 的文本内容很长,超出了一行的宽度,因此会自动换行。