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

空扰寡人 提交于 2019-12-06 06:16:00

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.

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>

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"

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