Skip to content Skip to sidebar Skip to footer

Android Layout Percentage/proportion Resize

I have 3 layouts. First and third ones are RelativeLayout and the middle one is TableLayout. What I want is the TableLayout should lay over 80% of screen. And 10% for the others. H

Solution 1:

Ok here are some steps:

  • set to the relative and table layouts android:layout_width to 0dp
  • in the parent layout add android:weightSum to 10
  • in each of the 3 child layouts add android:layout_weight and set the first & third to the value of 1 and the middle table layout to 8.

Here is the code and screenshot:

graphical editor view

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="horizontal"android:weightSum="10" ><RelativeLayoutandroid:id="@+id/leftPane"android:layout_width="0dp"android:layout_height="fill_parent"android:background="#336699"android:layout_weight="1"><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="10% wide"android:textAppearance="?android:attr/textAppearanceLarge" /></RelativeLayout><TableLayoutandroid:id="@+id/tableLayout1"android:layout_width="0dp"android:layout_height="wrap_content"android:layout_weight="8"><TableRowandroid:id="@+id/tableRow1"android:layout_width="wrap_content"android:layout_height="fill_parent"android:background="#00FFFF"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="row 1" /></TableRow><TableRowandroid:id="@+id/tableRow2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="#33FFFF" ><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="row 2" /></TableRow><TableRowandroid:id="@+id/tableRow3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="#66FFFF" ><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="row 3" /></TableRow><TableRowandroid:id="@+id/tableRow4"android:layout_width="wrap_content"android:layout_height="wrap_content"android:background="#99FFFF" ><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="row 4" /></TableRow></TableLayout><RelativeLayoutandroid:id="@+id/rightPane"android:layout_width="0dp"android:layout_height="fill_parent"android:background="#336699"android:layout_weight="1"><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="10% wide"android:textAppearance="?android:attr/textAppearanceLarge" /></RelativeLayout></LinearLayout>

Post a Comment for "Android Layout Percentage/proportion Resize"