小程序如何让四个view横向排列
时间: 2023-09-29 11:11:16 浏览: 57
要实现四个横向排列的 View,可以考虑使用 LinearLayout,将其设置为 horizontal 方向,然后将四个 View 添加到 LinearLayout 中即可。例如:
```xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
```
这样就可以实现四个 View 的横向排列,并且等分布局。其中,每个 View 的 layout_weight 属性设置为1,表示它们将平均占据布局的宽度。你也可以根据实际需求来调整各个 View 的 layout_weight 属性值,以实现自定义的宽度比例。