How to put a very long table layout inside the horizontal Scroll view in the CORRECT way?

浪子不回头ぞ 提交于 2019-12-22 18:29:16

问题


I tried looking at numerious examples and posts but none of them matches my problem.

I need to make a very long (horizontal) table with many columns so it is impossible to display in a single screen. And I don't want to spilt the table because it is important that I display my table in this way.

I have pasted my XML layout below (including the main important ones)

The thing is if I remove the code:

android:fillViewport="true"

from the HorizontalScrollView then my table inside it, gets squeezed in one place, especially at the left side of it. It doesn't even use much of this HorizontalScrollView container area.

And, If I use this code, then this HorizontalScrollView shows my whole table inside it - the columns are squeeze to make sure they fit in this scrollview.

I just want this scrollview to display only the content of my tablelayout that fits in the screen width, so I can scroll the remaining columns. But right now, I don't seem to get anywhere near.

So how do I solve my problem? Am I doing something wrong ?

Also here is my XML layout.

<?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>

回答1:


I got the answer. It was because I was using the

 android:stretchColumns="*" 

in the TableLayout.

Plus my TextView which were the columns, needed to some specific width size rather than just

android:layout_width="fill_parent" or "wrap_content"

Those were the problems.




回答2:


You should wrap your TableLayout with a LinearLayout.

<?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>




回答3:


You are using android:stretchColumns="*" you have to use some definite value with your layout_width instead of match_parent and wrap_content.

for ex. layout_width = "250dp"



来源:https://stackoverflow.com/questions/13674470/how-to-put-a-very-long-table-layout-inside-the-horizontal-scroll-view-in-the-cor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!