androidandroid-widgetandroid-scrollview

How can I make my layout scroll both horizontally and vertically?


I am using a TableLayout. I need to have both horizontal and vertical scrolling for this layout. By default I am able to get vertical scrolling in the view but horizontal scrolling is not working.

I am using Android SDK 1.5 r3. I have already tried android:scrollbars="horizontal".

I have read on some forums that in the cupcake update, horizontal scrolling is possible.

How can I make my layout scroll in both directions?


Solution

  • I was able to find a simple way to achieve both scrolling behaviors.

    Here is the xml for it:

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:scrollbars="vertical">
    
        <HorizontalScrollView 
            android:layout_width="320px" android:layout_height="fill_parent">
    
            <TableLayout
                android:id="@+id/linlay" android:layout_width="320px"
                android:layout_height="fill_parent" android:stretchColumns="1"
                android:background="#000000"/>
    
        </HorizontalScrollView>
    
    </ScrollView>