The Periodic Something Else The Periodic Something Else
Search
Percentage widths in Android

Here’s one that was bugging me for ages, setting the width child items of a horizontal LinearLayout using percentages without 10/15 minutes of trial and error.
Set the weightSum of the layout to 100 and the layout_width of each of the the children to 0px then you can set the layout_weight attribute of each of the children to the percentage width you want them to have. Shaboom!

<LinearLayout
	android:orientation="horizontal"
	android:id="@+id/toprow"
	android:weightSum="100"
	android:layout_width="fill_parent"
	android:layout_height="wrap_content">
		<TextView
		  android:id="@+id/text1"
			android:layout_width="0px"
			android:layout_weight="80"
			android:layout_height="wrap_content"/>
		<TextView android:id="@+id/custom_property"
			android:layout_width="0px"
			android:layout_weight="20"
			android:layout_height="wrap_content"/>
</LinearLayout>

Leave A Comment

Comment moderation is enabled. Your comment may take some time to appear.