Android: Span Columns In A TableRow

Setting a View like an ImageView or TextView within a TableRow spanning N number of columns can be done within the XML layout file using the android:layout_span attribute in the View object, not the TableRow.

Check out the sample xml code below. Since the second row contains 3 columns with 3 different ImageView objects and the first row contains only one ImageView, the android:layout_span is called to span the first row with 3 columns.

1
2
3
4
5
6
7
8
9
10
<TableLayout android:id="@+id/tableLayout1" android:layout_width="match_parent" android:layout_height="wrap_content" android:stretchColumns="*">
    	<TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content">
            <ImageView android:id="@+id/imageView7" android:layout_height="wrap_content" android:src="@drawable/imagelogo" android:layout_width="wrap_content" android:scaleType="centerInside" android:layout_span="3"></ImageView>          
        </TableRow>
    	<TableRow android:id="@+id/tableRow1" android:layout_width="wrap_content" android:layout_height="wrap_content">
    		<ImageView android:id="@+id/imageView1" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/image1"></ImageView>
    		<ImageView android:id="@+id/imageView2" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/image2"></ImageView>
    		<ImageView android:id="@+id/imageView3" android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/image3"></ImageView>        
        </TableRow>
</TableLayout>

Donations appreciated. Every little $ helps. Or click Google +1

Related Posts with Thumbnails