如何以正确的方式将很长的表格布局放入水平滚动视图中?

2024-04-11

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

我需要制作一个非常长(水平)的表格,其中有很多列,因此无法在单个屏幕中显示。我不想弄乱桌子,因为以这种方式展示我的桌子很重要。

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

问题是如果我删除代码:

android:fillViewport="true"

来自水平滚动视图然后我里面的桌子被挤在一个地方,特别是在它的左侧。它甚至没有使用太多 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>

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

 android:stretchColumns="*" 

在表格布局中。

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

android:layout_width="fill_parent" or "wrap_content"

这些就是问题所在。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何以正确的方式将很长的表格布局放入水平滚动视图中? 的相关文章

随机推荐