1

I have a TableLayout which is in a ScrollView, so I get vertical scroll. But when the columns exceed the screen with, I want the horizontal scroll also.

How can I do this? Please help.

Thanks, Farha

Farha Ansari
  • 5,855
  • 5
  • 26
  • 22

5 Answers5

6

take a look at this, it may be what u want.

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

        <HorizontalScrollView
            android:layout_width="fill_parent"          
            android:layout_height="fill_parent" >

                <TableLayout
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">

                    <TableRow 
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent">
                        <ImageView android:src="@drawable/icon"/>
                        <ImageView android:src="@drawable/tube"/>
                    </TableRow>

                    <TableRow ....
                    </TableRow>

                    <TableRow ....
                    </TableRow>

               </TableLayout>

       </HorizontalScrollView>

    </ScrollView>
whogiawho
  • 466
  • 9
  • 21
1

I would have a go with:

android:scrollbars="horizontal"

in your xml definition of the view, however if you are using a scrollview, it does not support horizontal scrolling, so the bar won't display...

Sephy
  • 50,022
  • 30
  • 123
  • 131
  • As I said, if you are using a ScrollView It won't work because It is not supported. look at the android doc and you will see that only vertical scroll is defined in methods: http://developer.android.com/intl/fr/reference/android/widget/ScrollView.html So you have to change your View container for a linearlayout for instance – Sephy Mar 11 '10 at 13:23
1

put attribute in scroll view tag.

android:scrollbars="horizontal"
Praveen
  • 90,477
  • 74
  • 177
  • 219
  • I think scrollview does not support horizontal scroll bar, see here http://groups.google.com/group/android-developers/browse_thread/thread/d675b7ed8ea72091 – Sephy Mar 11 '10 at 10:45
  • if u need access both scrollbars use pipe(|) between that. android:scrollbars="horizontal|vertical" – Praveen Mar 11 '10 at 12:31
  • yeah this method does not work. as I said before, horizontal scrolling is not supported by scrollview. if you wnt to set horizontal scroll, you need to use HorizontalScroll view, but then you don't have vertical scroll at the same time. – Sephy Mar 15 '10 at 09:19
1

horizontalscrollview http://developer.android.com/reference/android/widget/HorizontalScrollView.html was added in 1.5

dweebo
  • 3,222
  • 1
  • 17
  • 19
1

Place the HorizontalScrollView inside the ScrollView as mentioned above. Here is a tutorial on how to do just that: http://androiddevblog.blogspot.com/2009/12/creating-two-dimensions-scroll-view.html

123eloaded
  • 11
  • 1