Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Best Way to do Multicolumn ListView using Percentage Sizing
    text
    copied!<p>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. </p> <p>However, if I wrap the ListView in a TableLayout and TableRow, then it works.</p> <p>Attached is the main view layout XML that works. If you remove TableLayout and TableRow by removing the comment tags, it fails.</p> <p>Can anyone explain what is going on?</p> <p>Are there better ways to do this?</p> <p>===== Row Layout =====</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;!-- row.xml --&gt; &lt;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"&gt; &lt;TextView android:id="@+id/one" android:layout_width="0dip" android:layout_weight="25" android:textColor="#FFFFFF" android:text="One" android:layout_height="wrap_content"/&gt; &lt;TextView android:id="@+id/two" android:layout_width="0dip" android:layout_weight="25" android:textColor="#FFFFFF" android:text="Two" android:layout_height="wrap_content"/&gt; &lt;TextView android:id="@+id/three" android:layout_width="0dip" android:layout_weight="50" android:textColor="#FFFFFF" android:text="Three" android:layout_height="wrap_content"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>===== Main Layout =====</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;TableLayout android:id="@+id/mainlist" android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="0" android:paddingTop="4px" &gt; &lt;TableRow&gt; &lt;ListView android:id="@+id/lview" android:layout_width="wrap_content" android:layout_height="wrap_content" &gt; &lt;/ListView&gt; &lt;/TableRow&gt; &lt;/TableLayout&gt; &lt;/LinearLayout&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload