Adjust width of relative layouts in percent

How can I adjust the width of my 2 Relative Layouts correctly, so that the one to the left takes 0.25 of screen space and the one to the right takes 0.75? Inside the second relative layout there's a table layout with 3 columns, each of them should take 1/3 of table's size. Here's what I've tried with AXML, but it does not produce correct result (picture below) UPDATE now working:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:id="@+id/linearLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="1">
    <RelativeLayout
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight=".25">
        <LinearLayout
            android:id="@+id/buttonsLeft"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical">
            <Button
                android:id="@+id/buttonBack"
                android:text="@string/btnBack"
                android:layout_width="@dimen/myBtnWidth"
                android:layout_height="@dimen/myBtnHeight"
                android:layout_marginTop="@dimen/myBtnMargin"
                android:layout_marginLeft="@dimen/myBtnMargin" />
            <Button
                android:id="@+id/buttonStart"
                android:text="@string/btnStart"
                android:layout_width="@dimen/myBtnWidth"
                android:layout_height="@dimen/myBtnHeight"
                android:layout_marginTop="@dimen/myBtnMargin"
                android:layout_marginLeft="@dimen/myBtnMargin" />
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/notificationsNextorder"
                android:textSize="14sp"
                android:textStyle="bold" />
        </LinearLayout>
    </RelativeLayout>
    <RelativeLayout
        android:layout_width="0dip"
        android:layout_height="fill_parent"
        android:layout_weight=".75">
        <LinearLayout
            android:id="@+id/tableRight"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal"
            android:weightSum="1">
            <TableLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:id="@+id/tableLayout1">
                <TableRow
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:scrollbars="vertical">
                    <TextView
                        android:id="@+id/Text1"
                        android:padding="10sp"
                        android:textSize="@dimen/myTextSizeColHeader"
                        android:text="@string/bin"
                        android:layout_height="wrap_content"
                        android:layout_width="0dip"
                        android:layout_weight=".33"
                        android:gravity="left" />
                    <TextView
                        android:id="@+id/Text2"
                        android:padding="10sp"
                        android:textSize="@dimen/myTextSizeColHeader"
                        android:text="@string/item_customer"
                        android:layout_height="wrap_content"
                        android:layout_width="0dip"
                        android:layout_weight=".33"
                        android:gravity="center" />
                    <TextView
                        android:id="@+id/Text4"
                        android:padding="10sp"
                        android:textSize="@dimen/myTextSizeColHeader"
                        android:text="@string/nominal_actualQty"
                        android:layout_height="wrap_content"
                        android:layout_width="0dip"
                        android:layout_weight=".34"
                        android:gravity="right" />
                </TableRow>
                <ListView
                    android:id="@+id/whseActivHeadersList" />
            </TableLayout>
        </LinearLayout>
    </RelativeLayout>
</LinearLayout>

Result: enter image description here

1 answer

  • answered 2018-01-14 13:15 muhammed arshad k

    Add weightSum to parent linear layout. Check this answer

    <LinearLayout 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:weightSum="4">
    
        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1">
    
        </RelativeLayout>
    
        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="3">
    
        </RelativeLayout>