Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
like image 234
jbchichoko Avatar asked Dec 12 '25 10:12

jbchichoko


2 Answers

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.

like image 57
jbchichoko Avatar answered Dec 15 '25 02:12

jbchichoko


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>

like image 42
JiTHiN Avatar answered Dec 15 '25 01:12

JiTHiN



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!