希望在 Android 頁面底部放置四個 RelativeLayout,水平方向平均分配空間。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="96dp"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
使用 ConstraintLayout 的水平鏈條(Horizontal Chain)並設定 layout_constraintHorizontal_weight,也能達到等距分配。
0dp(MATCH_CONSTRAINT),搭配 layout_weight 使用。wrap_content,否則無法平均分配。LinearLayout 或 ConstraintLayout 作為根容器。