3

我尝试查看大量示例和帖子,但没有一个符合我的问题。

我需要制作一个包含许多列的很长(水平)的表格,因此不可能在单个屏幕上显示。而且我不想把表格弄得乱七八糟,因为以这种方式展示我的表格很重要。

我在下面粘贴了我的 XML 布局(包括主要的重要布局)

问题是如果我删除代码:

android:fillViewport="true"

Horizo​​ntalScrollView然后我的桌子在里面,被挤在一个地方,特别是在它的左侧。它甚至不使用这个 Horizo​​ntalScrollView 容器区域的大部分。

而且,如果我使用此代码,则此 Horizo​​ntalScrollView 会在其中显示我的整个表格 - 列被挤压以确保它们适合此滚动视图。

我只想让这个滚动视图只显示适合屏幕宽度的表格布局的内容,这样我就可以滚动剩余的列。但现在,我似乎没有靠近的地方。

那么我该如何解决我的问题呢?难道我做错了什么 ?

这也是我的 XML 布局。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>

<HorizontalScrollView
    android:id="@+id/horizontalScrollView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:scrollbars="horizontal"
    android:fillViewport="true">
    <TableLayout
        android:id="@+id/bot_scoreBoard"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/table_shape"
        android:orientation="horizontal"
        android:stretchColumns="*" >

        <TableRow
            android:layout_height="fill_parent"
            android:layout_margin="2dp"
            android:background="#ffffff"
            >
            <TextView
            />
               ....
            more than 16 columns of made using TextView
 ....
        </TableRow>
    </TableLayout>

</HorizontalScrollView>

</LinearLayout>
4

3 回答 3

3

我得到了答案。那是因为我在使用

 android:stretchColumns="*" 

在表格布局中。

加上我的 TextView 是列,需要一些特定的宽度大小,而不仅仅是

android:layout_width="fill_parent" or "wrap_content"

这些就是问题所在。

于 2012-12-03T20:25:56.863 回答
2

你应该TableLayoutLinearLayout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

<HorizontalScrollView
    android:id="@+id/horizontalScrollView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:scrollbars="horizontal" >

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

        <TableLayout
            android:id="@+id/bot_scoreBoard"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/table_shape"
            android:orientation="horizontal"
            android:stretchColumns="*" >

            <TableRow
                android:layout_height="fill_parent"
                android:layout_margin="2dp"
                android:background="#ffffff" >

                <TextView />
           ....
        more than 16 columns of made using TextView
     ....
            </TableRow>
        </TableLayout>
    </LinearLayout>
</HorizontalScrollView>

于 2012-12-03T01:24:29.373 回答
0

你正在使用android:stretchColumns="*"你必须使用一些明确的价值layout_width来代替match_parentand wrap_content

例如。layout_width = "250dp"

于 2016-03-28T14:55:32.687 回答