Android Percentage Layout Height Android Percentage Layout Height xml xml

Android Percentage Layout Height


There is an attribute called android:weightSum.

You can set android:weightSum="2" in the parent linear_layout and android:weight="1" in the inner linear_layout.

Remember to set the inner linear_layout to fill_parent so weight attribute can work as expected.

Btw, I don't think its necesary to add a second view, altough I haven't tried. :)

<LinearLayout    android:layout_height="fill_parent"    android:layout_width="fill_parent"    android:weightSum="2">    <LinearLayout        android:layout_height="fill_parent"        android:layout_width="fill_parent"        android:layout_weight="1">    </LinearLayout></LinearLayout>


You could add another empty layout below that one and set them both to have the same layout weight. They should get 50% of the space each.


android:layout_weight=".YOURVALUE" is best way to implement in percentage

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <TextView        android:id="@+id/logTextBox"        android:layout_width="fill_parent"        android:layout_height="0dp"        android:layout_weight=".20"        android:maxLines="500"        android:scrollbars="vertical"        android:singleLine="false"        android:text="@string/logText" >    </TextView></LinearLayout>