Android TableRow跨度不适用于动态添加的行

Android TableRow跨度不适用于动态添加的行,android,tablelayout,tablerow,Android,Tablelayout,Tablerow,我遇到以下问题:在滚动视图中动态添加行到TableLayout。行遵循以下模式: 第1行:单元格跨越整个表格 第2行:两个单元格 第3行:单元格跨越整个表格 … 第N行:两个单元格 问题在于,一个单元格跨行的行实际上根本不跨行。它到达屏幕中间的某个点,只是在高度上包裹。 以下是Android 2.3.3下的问题截图: 请注意,下面的示例过于简单(但仍然不起作用)。他们已准备好尝试-只需创建文件。我进行了调试,似乎布局参数在某种程度上消失了。此外,如果TableLayout是在main.xml文

我遇到以下问题:在滚动视图中动态添加行到TableLayout。行遵循以下模式:

第1行:单元格跨越整个表格
第2行:两个单元格
第3行:单元格跨越整个表格

第N行:两个单元格

问题在于,一个单元格跨行的行实际上根本不跨行。它到达屏幕中间的某个点,只是在高度上包裹。

以下是Android 2.3.3下的问题截图:

请注意,下面的示例过于简单(但仍然不起作用)。他们已准备好尝试-只需创建文件。我进行了调试,似乎布局参数在某种程度上消失了。此外,如果TableLayout是在main.xml文件中硬编码的,则没有问题。不幸的是,我需要动态生成视图

TestProject.java main.xml

表_row_columns.xml

表_span_row.xml

我尝试了requestLayout并使其无效,但没有效果


另外,我还欢迎关于如何在ScrollView中动态替换视图的建议

好的,我找到了解决方案。只需删除我希望跨越整个表的行的TableRow标记

表span\u 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>


我不知道如果我换成3列,并想跨越其中两列上的一个单元格,会发生什么:)

可能会对某人有所帮助。即使是这个问题也已经两年多了,我现在也看到了同样的错误。也就是说,rowSpanLayout.span=2;不起作用。但在xml布局中,它是有效的。 我找到了可行的解决方案: 1.使用布局属性创建layour xml文件注入:

 <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>

它起作用了

我在这里找到了类似问题的答案:在XML文件中,您有对象check1。从中获取参数,然后将其用于tw。你没有支票怎么办?因为我尝试创建tw,所以执行blp=(TableRow.LayoutParams)检查1.getLayoutParams();,我得到blp空值,我找到了。看看这里,看看如何避免检查1的需要。
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent" android:layout_height="wrap_content">
    <TextView android:layout_height="wrap_content" android:text="This is column one" android:layout_weight="1" android:layout_width="fill_parent"></TextView>
    <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Column 2"></TextView>
</TableRow>
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_height="wrap_content" android:layout_width="fill_parent">
    <LinearLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_span="2" 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>
        <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="... but it does not do so"></TextView>
    </LinearLayout>
</TableRow>
<?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>
 <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);