Columns in ListView Android

You can use layout_weight in conjuntion with layout_width of 0 like this in your item layout xml:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"  
    android:id="@+id/relativeLayout1" 
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent" >  

    <TextView  
         android:id="@+id/text1" 
         android:layout_width="0dp"  
         android:layout_height="wrap_content" 
         android:layout_weight="1"/>  

    <TextView  
         android:id="@+id/text2" 
         android:layout_width="0dp"  
         android:layout_height="wrap_content" 
         android:layout_weight="2"/>
</LinearLayout>

Essentially the layout_width of 0dp forces all the text views to have no width. Since spare width in the linear layout is dished out according the layout_weight after the width of the text views has been determined you start with an even playing field among the text boxes who all have the same width (0). Without the 0 width, the text boxes start off at different widths and adding extra space (via the layout_weight) still leaves the text boxes different width.


Consider using a TableLayout instead of a ListView. This is designed to have rows and columns. See Hello TableLayout.

To add rows programatically, you can inflate the TableRow and call addView on the TableLayout.


You could do one of these instead of wrap_content on the TextViews:

android:layout_width="40dip"

the above sets the density-independent width, or

android:layout_weight="2"

which you can use to set the percentage width on each text view.

Also see this post and the link: What is the difference between "px", "dp", "dip" and "sp" on Android?