修复了第一个TableRow android

修复了第一个TableRow android,android,tablerow,android-tablelayout,Android,Tablerow,Android Tablelayout,我在这个表中有一个表布局,我定义了一个tablerow,其中有4个EditText作为列标题 我的问题是,我想把这一静态行作为一个固定的位置,所以当我向下滚动屏幕时,这一行的位置没有改变 我从DB动态加载其他行 谢谢你的帮助 这是我的xml代码: <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/horizontalScrollView1

我在这个表中有一个表布局,我定义了一个tablerow,其中有4个EditText作为列标题

我的问题是,我想把这一静态行作为一个固定的位置,所以当我向下滚动屏幕时,这一行的位置没有改变

我从DB动态加载其他行

谢谢你的帮助

这是我的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>

首先, 为什么需要
LinearLayout
内部
ScrollView
TableLayout
将垂直排列行,而不使用
LinearLayout

第二,大量的视图将大大降低应用程序的性能。 考虑将<代码> TabelayayOut/<代码>替换为…可能是一个
列表视图
或为您自己的组件编写代码。据我所知,您需要一个带有纯文本字段的简单表——实现一个简单、快速且易于使用的组件并不难

第三,解决方案-只需将标题行放在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

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

希望这有帮助

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

首先…为什么在horizontalscrollview中使用scrollview?第二,如果你不想某个视图不滚动,就把它放在滚动视图之外。我也尝试用两个表来实现这一点,但效果不好。你有你想要实现的布局的图像吗,所以我可以给你正确的方法来构建它。非常感谢你,我成功了。我的错误是初学者的错误。我用两个表完成了这项工作,在下表中我定义了一个空文本视图,如标题。