0

我有一个ListView我从大约 10 列的数据表中加载数据,所以我需要用户能够水平滚动以查看所有数据。现在我想把 Columns 放在 的顶部ListView,但是在水平滚动里面。不幸的是,我不知道如何将 放在TextBoxes顶部ListView,而是放在水平滚动条内。它总是ListBoxTextBoxes. 甚至有可能做到这一点?

我的 XML 代码如下:

<HorizontalScrollView
    android:id="@+id/horizontalScrollView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_below="@+id/imageView2" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="527dp"
        android:orientation="horizontal" >

        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="50sp"
            android:layout_weight="1"
            android:headerDividersEnabled="true" >
        </ListView>

        <TextView
            android:id="@+id/code"
            android:layout_width="110sp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="0dp"
            android:layout_marginStart="1dp"
            android:layout_alignParentTop="true"
            android:maxLines="1"
            android:text="@string/lChangedTime"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textSize="17sp" />

        <TextView
            android:id="@+id/manufacturer"
            android:layout_width="70sp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="11dp"
            android:maxLines="1"
            android:text="manufacturer"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textSize="17sp" />

        <TextView
            android:id="@+id/name"
            android:layout_width="200sp"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="11dp"
            android:layout_toRightOf="@+id/manufacturer"
            android:maxLines="1"
            android:text="@string/lCustomerName"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textSize="20sp" />

        <TextView
            android:id="@+id/visc40"
            android:layout_width="50sp"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="11dp"
            android:layout_toRightOf="@+id/name"
            android:maxLines="1"
            android:text="visc40"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textSize="17sp" />

        <TextView
            android:id="@+id/visc100"
            android:layout_width="50sp"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="11dp"
            android:layout_toRightOf="@+id/visc40"
            android:maxLines="1"
            android:text="visc100"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textSize="17sp" />

    </LinearLayout>

</HorizontalScrollView>
4

1 回答 1

1

如果我理解正确,那么您需要将文本视图嵌套在另一个布局中。

让我告诉你我的意思

<HorizontalScrollView
        android:id = "@+id/horizontalScrollView1"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_alignParentLeft = "true"
        android:layout_alignParentRight = "true"
        android:layout_below = "@+id/imageView2">

    <LinearLayout
            android:layout_width = "match_parent"
            android:layout_height = "527dp"
            android:orientation = "vertical">

        <LinearLayout
                android:layout_width = "match_parent"
                android:layout_height = "wrap_content"
                android:orientation = "horizontal">

            <TextView
                    android:id = "@+id/code"
                    android:layout_width = "110sp"
                    android:layout_height = "wrap_content"
                    android:layout_marginLeft = "0dp"
                    android:layout_marginStart = "1dp"
                    android:layout_alignParentTop = "true"
                    android:maxLines = "1"
                    android:text = "@string/lChangedTime"
                    android:textAppearance = "?android:attr/textAppearanceLarge"
                    android:textSize = "17sp"/>

            <TextView
                    android:id = "@+id/manufacturer"
                    android:layout_width = "70sp"
                    android:layout_height = "wrap_content"
                    android:layout_marginLeft = "11dp"
                    android:maxLines = "1"
                    android:text = "manufacturer"
                    android:textAppearance = "?android:attr/textAppearanceLarge"
                    android:textSize = "17sp"/>

            <TextView
                    android:id = "@+id/name"
                    android:layout_width = "200sp"
                    android:layout_height = "wrap_content"
                    android:layout_alignParentTop = "true"
                    android:layout_marginLeft = "11dp"
                    android:layout_toRightOf = "@+id/manufacturer"
                    android:maxLines = "1"
                    android:text = "@string/lCustomerName"
                    android:textAppearance = "?android:attr/textAppearanceLarge"
                    android:textSize = "20sp"/>

            <TextView
                    android:id = "@+id/visc40"
                    android:layout_width = "50sp"
                    android:layout_height = "wrap_content"
                    android:layout_alignParentTop = "true"
                    android:layout_marginLeft = "11dp"
                    android:layout_toRightOf = "@+id/name"
                    android:maxLines = "1"
                    android:text = "visc40"
                    android:textAppearance = "?android:attr/textAppearanceLarge"
                    android:textSize = "17sp"/>

            <TextView
                    android:id = "@+id/visc100"
                    android:layout_width = "50sp"
                    android:layout_height = "wrap_content"
                    android:layout_alignParentTop = "true"
                    android:layout_marginLeft = "11dp"
                    android:layout_toRightOf = "@+id/visc40"
                    android:maxLines = "1"
                    android:text = "visc100"
                    android:textAppearance = "?android:attr/textAppearanceLarge"
                    android:textSize = "17sp"/>
        </LinearLayout>

        <ListView
                android:id = "@+id/listView1"
                android:layout_width = "match_parent"
                android:layout_height = "wrap_content"
                android:layout_marginTop = "50sp"
                android:layout_weight = "1"
                android:headerDividersEnabled = "true">
        </ListView>
    </LinearLayout>
</HorizontalScrollView>
于 2013-05-22T21:47:00.500 回答