要在Android中实现横向等分,可以使用LinearLayout来实现。以下是一种方法:
1. 在XML布局文件中定义一个水平方向的LinearLayout:
```xml
android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal">
```
2. 在LinearLayout内部定义要分隔的子项,并给每个子项设置相同的权重(weight)属性:
```xml
android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1">
android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1">
android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1">
```
通过设置layout_width为0dp并设置layout_weight属性为相同的值,可以使每个子项平均分配LinearLayout的宽度。
3. 可以继续添加更多的子项,并为每个子项设置相同的layout_weight属性,以实现横向等分效果。
这样,使用LinearLayout和layout_weight属性可以简单地实现Android中的横向等分。