Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can we make table layout to scroll both ways ( horizontally, vertically)

I am having a table defined in XML file, which currently set to Scroll vertically. But i also want it scroll horizontally as required.

Here is the code of XML in use

<?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>
like image 965
Amit Avatar asked Mar 02 '10 10:03

Amit


People also ask

How to make LinearLayout horizontal scrollable in Android?

Step 1: Choose your Parent layout. In the example I have choose a LinearLayout with with horizontal orientation. Step 2: Add HorizontalScrollView as a sub-view with layout_width and layout_height as match_parent. You may add padding if you want.

How to make a view scrollable in Android?

In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it. A ScrollView supports Vertical scrolling only, so in order to create a horizontally scrollable view, HorizontalScrollView is used.

Can scroll vertically Android?

ScrollView is used to scroll the child elements of palette inside ScrollView. Android supports vertical scroll view as default scroll view. Vertical ScrollView scrolls elements vertically. Android uses HorizontalScrollView for horizontal ScrollView.


1 Answers

I had the same problem and I solved it introducing a HorizontalScrollView as a child of the ScrollView and then the tableLayout as a child of the HorizontalScrollView:

like image 182
Nemesis Avatar answered Oct 14 '22 04:10

Nemesis