Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android Relative Layout Example
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="One"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Two"
android:id="@+id/textView2"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView"
android:layout_toEndOf="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Three"
android:id="@+id/textView3"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView2"
android:layout_toEndOf="@+id/textView2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Four"
android:id="@+id/textView4"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView3"
android:layout_toEndOf="@+id/textView3" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<TextView
android:layout_width="200dp"
android:layout_height="150dp"
android:text="One"
android:id="@+id/textView" />
<TextView
android:layout_width="200dp"
android:layout_height="150dp"
android:text="Two"
android:id="@+id/textView2"
android:layout_toRightOf="@+id/textView"/>
<TextView
android:layout_width="200dp"
android:layout_height="150dp"
android:text="Three"
android:id="@+id/textView3"
android:layout_below="@+id/textView" />
<TextView
android:layout_width="200dp"
android:layout_height="150dp"
android:text="Four"
android:id="@+id/textView4"
android:layout_toRightOf="@+id/textView3"
android:layout_below="@+id/textView2" />
</RelativeLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment