I have tried the recommended approach for percentage sizing of rows in LinearLayout using layout_weight, with no success when wrapped in a ListView. The row layout XML looks fine in Eclipse preview, but the columns are run together in the actual test app.
However, if I wrap the ListView in a TableLayout and TableRow, then it works.
Attached is the main view layout XML that works. If you remove TableLayout and TableRow by removing the comment tags, it fails.
Can anyone explain what is going on?
Are there better ways to do this?
===== Row Layout =====
<?xml version="1.0" encoding="utf-8"?>
<!-- row.xml -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:orientation="horizontal">
<TextView android:id="@+id/one"
android:layout_width="0dip"
android:layout_weight="25"
android:textColor="#FFFFFF"
android:text="One"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/two"
android:layout_width="0dip"
android:layout_weight="25"
android:textColor="#FFFFFF"
android:text="Two"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/three"
android:layout_width="0dip"
android:layout_weight="50"
android:textColor="#FFFFFF"
android:text="Three"
android:layout_height="wrap_content"/>
</LinearLayout>
===== Main Layout =====
<?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" >
<TableLayout
android:id="@+id/mainlist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:stretchColumns="0"
android:paddingTop="4px" >
<TableRow>
<ListView
android:id="@+id/lview"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ListView>
</TableRow>
</TableLayout>
</LinearLayout>
Remove the table layout and tablerow and just set your ListView layout_width to match_parent
edit: or match_parent or fill_parent, they are synonymous.