Set equal width of columns in table layout in Android

AndroidTablelayout

Android Problem Overview


> Possible Duplicate:
> XML Table layout? Two EQUAL-width rows filled with equally width buttons?

I am using TableLayout to show list of data in 4 columns.

Problem description:

I am unable to set equal width of all 4 columns, which are in my TableLayout. I am putting my layout code, which I am using...

<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="0">
  		<TableRow>
  			<TextView android:text="table header1" android:layout_width="wrap_content" android:layout_height="wrap_content" 
  				 android:textSize="10dip" android:textStyle="bold"/> 	
  			<TextView android:text="table header2" android:layout_width="wrap_content" android:layout_height="wrap_content" 
  				android:textSize="10dip" android:textStyle="bold"/> 
  			<TextView android:text="table header3" android:layout_width="wrap_content" android:layout_height="wrap_content" 
  				android:textSize="10dip" android:textStyle="bold"/> 
  			<TextView android:text="table header4" android:layout_width="wrap_content" android:layout_height="wrap_content" 
  				android:textSize="10dip" android:textStyle="bold"/> 		
  		</TableRow>
  	</TableLayout>

How should I rewrite this layout to show 4 columns with equal sizes?

Android Solutions


Solution 1 - Android

Try this.

It boils down to adding android:stretchColumns="*" to your TableLayout root and setting android:layout_width="0dp" to all the children in your TableRows.

<TableLayout
    android:stretchColumns="*"   // Optionally use numbered list "0,1,2,3,..."
>
    <TableRow
        android:layout_width="0dp"
    >

Solution 2 - Android

Change android:stretchColumns value to *.

Value 0 means stretch the first column. Value 1 means stretch the second column and so on.

Value * means stretch all the columns.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPankaj KumarView Question on Stackoverflow
Solution 1 - AndroidSherif elKhatibView Answer on Stackoverflow
Solution 2 - AndroidiTurkiView Answer on Stackoverflow