27

I am totally confused in table layout scroll. I have to implement table with horizontal and vertical scrolling. I have also saw table fix header example but tablefixheader sample have used adapter to set data but i require add-view method in table layout. I have used below code but it couldn't support both ways scrolling

      <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scrollbars="vertical" >

        <HorizontalScrollView
            android:layout_width="match_parent"
            android:layout_height="fill_parent" 
            android:fadeScrollbars="false">

            <TableLayout
                android:id="@+id/tableLayoutId"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </HorizontalScrollView>
    </ScrollView>
Emil Adz
  • 40,709
  • 36
  • 140
  • 187
user1811379
  • 385
  • 1
  • 4
  • 12

2 Answers2

69

This is how I implemented it and works for me:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
 <ScrollView 
    android:id="@+id/layout" 
    android:layout_height="match_parent"         
    android:scrollbars="horizontal|vertical" 
    android:layout_width="match_parent"     
    android:layout_marginTop="5dip"     
    android:scrollbarStyle="outsideInset"
    android:fillViewport="true"> 

    <HorizontalScrollView 
        android:id="@+id/horizontalView" 
        android:layout_height="wrap_content"     
        android:scrollbars="horizontal|vertical" 
        android:layout_width="wrap_content"     
        android:layout_marginTop="5dip">

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/tlGridTable" >   
        </TableLayout>
    </HorizontalScrollView>
</ScrollView>
</LinearLayout>

Take a look at this code and see if this helps.

Emil Adz
  • 40,709
  • 36
  • 140
  • 187
  • 1
    Great +1. You should add a little explanation why it works =) – user2336315 May 18 '13 at 11:19
  • My guess would be that it works because of this line android:scrollbars="horizontal|vertical" in both scrollViews that the OP has missed. – Emil Adz May 19 '13 at 11:55
  • You should change the outsideInset value to outsideOverlay, otherwise the TableLayout's width won't match your parents width. It won't fill up the screen. – Hampel Előd May 20 '15 at 07:30
  • I have some problem in ScrollView please help me, i tried your solution but not success @EmilAdz http://stackoverflow.com/questions/38588702/why-my-scrollview-not-working-properly – Karthi Jul 26 '16 at 13:49
  • @KarthiVenture, the question you asked is not related to this code. This code design to enable horizontal and vertical scroll, where you want to apply only vertical scroll in you case. – Emil Adz Jul 26 '16 at 15:18
  • okay thanks bro but how to fix my problem ? what i make mistake? @EmilAdz – Karthi Jul 27 '16 at 04:22
5

add like this

<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="match_parent"
            android:layout_height="match_parent">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/rv_pins"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbarStyle="outsideOverlay"
                android:scrollbars="horizontal" />
        </HorizontalScrollView>

    </ScrollView>
saigopi.me
  • 14,011
  • 2
  • 83
  • 54