Android 如何以正确的方式在水平滚动视图中放置很长的表格布局?
我试着看了无数的例子和帖子,但没有一个和我的问题相符 我需要制作一个非常长(水平)的表格,其中包含许多列,因此不可能在单个屏幕中显示。我不想把表弄乱,因为以这种方式显示表很重要 我已经在下面粘贴了我的XML布局(包括主要的重要布局) 问题是如果我删除代码:Android 如何以正确的方式在水平滚动视图中放置很长的表格布局?,android,horizontalscrollview,android-tablelayout,Android,Horizontalscrollview,Android Tablelayout,我试着看了无数的例子和帖子,但没有一个和我的问题相符 我需要制作一个非常长(水平)的表格,其中包含许多列,因此不可能在单个屏幕中显示。我不想把表弄乱,因为以这种方式显示表很重要 我已经在下面粘贴了我的XML布局(包括主要的重要布局) 问题是如果我删除代码: android:fillViewport="true" 从水平滚动视图中,我在其中的桌子被挤在一个地方,特别是在它的左侧。它甚至不使用这个HorizontalScrollView容器区域 以及, 如果我使用这段代码,那么这个Horizont
android:fillViewport="true"
从水平滚动视图中,我在其中的桌子被挤在一个地方,特别是在它的左侧。它甚至不使用这个HorizontalScrollView容器区域
以及,
如果我使用这段代码,那么这个HorizontalScrollView会在其中显示我的整个表-列会被挤压以确保它们适合这个scrollview
我只希望这个滚动视图只显示适合屏幕宽度的tablelayout的内容,这样我就可以滚动其余的列。但是现在,我似乎没有什么进展
那么我该如何解决我的问题呢?我做错什么了吗
这也是我的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>
....
使用TextView制作了超过16列的
....
您应该用线性布局
包装您的表格布局
<?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>
....
使用TextView制作了超过16列的
....
我得到了答案。那是因为我用的是
android:stretchColumns="*"
在表格布局中
加上我的文本视图,这些列需要特定的宽度大小,而不仅仅是
android:layout_width="fill_parent" or "wrap_content"
这些就是问题所在。您使用的是
android:stretchColumns=“*”
您必须对布局宽度使用一些确定的值,而不是匹配父项和包装内容
例如,layout\u width=“250dp”
我不确定这会有什么帮助。我试过了,但它仍然没有达到我想要的效果。