<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/boxLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FF0000"
android:layout_marginBottom="8dp" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#00FF00"
android:layout_marginBottom="8dp" />
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#0000FF" />
</LinearLayout>We use a vertical LinearLayout to stack boxes vertically.
Each View acts as a colored box with a background color: red, green, and blue.
Setting layout_height to 0dp and layout_weight to 1 makes all boxes share equal height.
Margins add space between boxes for better look.
The boxes fill the width because layout_width is match_parent.