Skip to content

Instantly share code, notes, and snippets.

@silwar
Created February 8, 2017 10:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save silwar/ba2679baf5d5681796228e2fe9d01645 to your computer and use it in GitHub Desktop.
Save silwar/ba2679baf5d5681796228e2fe9d01645 to your computer and use it in GitHub Desktop.
This is Android layout file to show how to divide views equally using Relativelayout. This better practice than using layout weights
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/vertical_divider"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_centerHorizontal="true" />
<View
android:id="@+id/horizontal_divider"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_centerVertical="true" />
<LinearLayout
android:id="@+id/firstLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/horizontal_divider"
android:layout_toLeftOf="@id/vertical_divider"
android:background="#4285f4"
android:orientation="vertical" />
<LinearLayout
android:id="@+id/secondLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/horizontal_divider"
android:layout_toRightOf="@id/vertical_divider"
android:background="#34A853"
android:orientation="vertical" />
<LinearLayout
android:id="@+id/thirdLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/horizontal_divider"
android:layout_toLeftOf="@id/vertical_divider"
android:background="#FBBC05"
android:orientation="vertical" />
<LinearLayout
android:id="@+id/fourthLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/horizontal_divider"
android:layout_toRightOf="@id/vertical_divider"
android:background="#EA4335"
android:orientation="vertical" />
</RelativeLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment