android - 修复了第一个 TableRow android

标签 android tablerow android-tablelayout

我在这个表格中有一个表格布局,我定义了一个表格行,其中有 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>

最佳答案

首先, 为什么在 ScrollView 中需要 LinearLayoutTableLayout 将在没有 LinearLayout 的情况下垂直展开行。

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

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

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

希望这对您有所帮助。

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

关于android - 修复了第一个 TableRow android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15876275/

相关文章:

android - E/媒体播放器 : Error (-38, 0)

android - 向表格行添加选择功能

android - 只听一个关键词的持续语音识别

android - 没有以编程方式为 TableRow 设置填充?

html - 表格行上的圆 Angular

java - 使用 for 循环设置 TextView 文本,以便显示多行

Android:按列对表格布局内容进行排序

android - 如何使 TableLayout 的宽度相同并换行内容

android - 在 Firebase RecyclerView 中添加或删除子项时出现重复列表行

android - 如何在从通知调用的 Activity 中按回时留在应用程序中?