It seems that there is an attribute doing that : layout_span
UPDATE: This attribute must be applied to the children of the TableRow. NOT to the TableRow itself.
Just to complete the answer, the layout_span attribute must be added to the child, not to TableRow.
This snippet shows the third row of my tableLayout, which spans for 2 columns.
<TableLayout>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:text="@string/create" />
</TableRow>
</TableLayout>
And this is how you do it programmatically
//theChild in this case is the child of TableRow
TableRow.LayoutParams params = (TableRow.LayoutParams) theChild.getLayoutParams();
params.span = 2; //amount of columns you will span
theChild.setLayoutParams(params);
You have to use layout_weight to fill the entire row otherwise it still fills left or right column of table layout.
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="2"
android:layout_weight="1"
android:text="ClickMe" />
</TableRow>
Maybe this will help someone. I tried the solution with layout_span
but this not working for me. So I solved the problem with this trick. Just use LinearLayout
in place of TableRow
where you need colspan, that's all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With