SpencerChantler123
SpencerChantler123

Reputation: 366

How to split an Android XML into three equal layout rectangles?

How do I split an Android XML view into three equal layout rectangles like the image below?

enter image description here

Upvotes: 2

Views: 2940

Answers (2)

josephus
josephus

Reputation: 8304

You want to use a vertical LinearLayout, like this:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="3" >

    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:background="#ff0000" >
    </FrameLayout>
    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:background="#00ff00" >
    </FrameLayout>
    <FrameLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:background="#0000ff" >
    </FrameLayout>

</LinearLayout>

Upvotes: 5

Qadir Hussain
Qadir Hussain

Reputation: 8856

You can use linear-layout in this case with a orientation:Vertical

try this out

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<Button
    android:id="@+id/button2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="0.17"
    android:text="Button" />

<Button
    android:id="@+id/button1"
    android:layout_width="match_parent"
    android:layout_height="114dp"
    android:layout_weight="0.11"
    android:text="Button" />

<Button
    android:id="@+id/button3"
    android:layout_width="334dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.17"
    android:text="Button" />

 </LinearLayout>

Upvotes: 0

Related Questions