How can we make a table layout for scrolling in both directions (horizontal, vertical)

I have a table defined in an XML file that is currently configured to scroll vertically. But I also want it to scroll horizontally as required.

Here is the code used by XML

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
     android:scrollbars="vertical" 
     android:layout_height="fill_parent" 
     android:layout_width="fill_parent">

    <TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:stretchColumns="0,1,2"
        android:id="@+id/tLayout"
        android:scrollbars="vertical"
        >   
        <TableRow
            android:layout_width="fill_parent">
            <TextView
                android:padding="3dip"
                android:gravity="left"
                android:text="Name"
                />
            <TextView
                android:padding="3dip"
                android:gravity="left"
                android:text="Address"
                />
            <TextView
                android:padding="3dip"
                android:gravity="left"
                android:text="Age"
                />
        </TableRow>
    </TableLayout>
</ScrollView>
+5
source share
3 answers

I had the same problem, and I decided that it represents HorizontalScrollView as a child of ScrollView, and then tableLayout as a child of HorizontalScrollView:

                   

+8
source

You can check out this library I made: https://github.com/InQBarna/TableFixHeaders

, Adapeter. .

+2

HorizontalScrollView - ?

http://developer.android.com/reference/android/widget/HorizontalScrollView.html

Perhaps add some kind of layout (LinearLayout, Relativelayout, etc.) to the root of your xml?

0
source

All Articles