I have the following problem spanning dynamically added rows to a TableLayout inside a scroll view. The rows follow this pattern:
Row 1: Cell spanned over the whole
May be it will help to somebody. Even this question was more than 2 years I see the same bug right now. That is, rowSpanLayout.span = 2; doesn't work. But in xml layout_span it works. I found the workable solution: 1. create the layour xml file injection with layout properties:
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone">
<TextView
android:id="@+id/check1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_span="3"
android:text="TextView" />
</TableRow>
</TableLayout>
TableRow.LayoutParams blp; blp = (TableRow.LayoutParams)check1.getLayoutParams(); blp.width = 100; blp.height = 50; TextView tw = new TextView(this); tw.setTextSize(tsEL); tw.setLayoutParams(blp); tw.setText(R.string.empty); tr.addView(tw);
It works.
OK, I found the solution. It was simply to drop the TableRow tag for the row that I wanted to span across the table.
table_span_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent"
android:background="#FF333333">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:text="This should span on the whole row" />
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="... and now it does" />
</LinearLayout>
I do not know what will happen if I had 3 columns instead and wanted to span one of the cells on two of them :)