1

我在这个表格中有一个表格布局,我定义了一个带有 4 个编辑文本的表格行作为列标题。

我的问题是我想将此静态行设为固定位置,因此当我向下滚动屏幕时,此行位置不会改变。

我从数据库动态加载其他行。

感谢您的帮助!

这是我的 xml 代码:

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/horizontalScrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="@drawable/background">
    <ScrollView 
        android:id="@+id/scrollViewPhysicalExam"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <LinearLayout 
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <TableLayout 
                    android:id="@+id/TLArchiveHeader"
                    android:layout_height="wrap_content"
                    android:layout_width="match_parent">

                    <TableRow style="@style/HeaderRow">

                        <TextView
                        style="@style/HeaderText"
                        android:layout_width="200dp"
                        android:text="Owner name"/>

                    <TextView
                        style="@style/HeaderText"
                        android:layout_width="200dp"
                        android:text="Phone" />

                    <TextView
                        style="@style/HeaderText"
                        android:layout_width="200dp"
                        android:text="Address" />

                    <TextView
                        style="@style/HeaderText"
                        android:layout_width="200dp"
                        android:text="Mail" />
                    <TextView
                        style="@style/HeaderText"
                        android:layout_width="200dp"
                        android:text="Fax" />

                </TableRow>

            </TableLayout>

        </LinearLayout>
  </ScrollView>
</HorizontalScrollView>
4

1 回答 1

3

首先,为什么你需要LinearLayoutinside ScrollViewTableLayout将不带LinearLayout.

其次 - 大量的视图会显着降低应用程序的性能。考虑替换TableLayout为.. 可能是 aListView或编写您自己的组件。据我了解,您需要一个带有纯文本字段的简单表格 - 实现单个、快速且易于使用的组件并不难。

第三 - 解决方案 - 只需将标题行放在 ScrollView 之外,如下所示:

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/horizontalScrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" 
    android:background="@drawable/background">

    <TableLayout 
        android:id="@+id/TLArchiveHeader"
        android:layout_height="wrap_content"
        android:layout_width="match_parent">
        <TableRow style="@style/HeaderRow">
            <TextView
            style="@style/HeaderText"
            android:layout_width="200dp"
            android:text="Owner name"/>
            <TextView
                style="@style/HeaderText"
                android:layout_width="200dp"
                android:text="Phone" />
            <TextView
                style="@style/HeaderText"
                android:layout_width="200dp"
                android:text="Address" />
            <TextView
                style="@style/HeaderText"
                android:layout_width="200dp"
                android:text="Mail" />
            <TextView
                style="@style/HeaderText"
                android:layout_width="200dp"
                android:text="Fax" />
        </TableRow>
    </TableLayout>
    <ScrollView 
        android:id="@+id/scrollViewPhysicalExam"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TableLayout 
            android:id="@+id/TLArchiveRowPlaceholder"
            android:layout_height="wrap_content"
            android:layout_width="match_parent">
        </TableLayout>
    </ScrollView>
</HorizontalScrollView>

将行添加到TLArchiveRowPlaceholder.

但在这种情况下,你需要有固定的列宽。或者在每次主表更新后更新标题列宽,以免标题错位。

希望这可以帮助。

我的错。为什么答案在评论中?之前没看过=)

于 2013-04-08T10:24:26.273 回答