0

我知道有几个关于这个的帖子,但我无法让它工作。我想要一个带有标题的表格,该表格在滚动表格内容时保持可见。我喜欢这种方法:http ://www.entreotrascosas.net/creating-dynamic-scrollable-fixed-header-tables-in-android/

这是我的xml。我有两个 TableLayout,一个用于标题,一个用于内容。我用一排填充它们,layout_height设置为0dp.

<TableLayout
    android:id="@+id/headerLayout"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" >
    <TableRow
       android:id="@+id/hiddenLongestRow"
       android:layout_width="wrap_content"
       android:layout_height="0dp"  />
</TableLayout>

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/headerLayout"
    android:fadeScrollbars="false" > 
    <TableLayout
        android:id="@+id/contentLayout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TableRow
            android:id="@+id/hiddenHeaderRow"
            android:layout_width="wrap_content"
            android:layout_height="0dp"  />     
    </TableLayout>   
</ScrollView>

然后,我用我的值和在我的 xml 中指定的行以标题/最长行的虚拟值以编程方式填充表。现在,两个表的列具有相同的宽度。到目前为止,一切都很好。

但现在我需要两个虚拟行消失。据说将高度设置为0dp可以做到这一点,但对我来说不是,行总是可见的。

我尝试以编程方式将 LayoutParams 的高度设置为 0,但没有帮助。将可见性设置为 INVISIBLE 或 GONE 不起作用。我还可以做些什么?

4

1 回答 1

0

您可以尝试删除它:

TableRow row = (TableRow)findViewById(R.id.hiddenHeaderRow);
table.removeView(row);
于 2015-04-15T13:12:22.667 回答