Aditi K
Aditi K

Reputation: 1554

How can i make Table layout rows scrollable In android?

I am using Table layout Inside scrollview it makes whole Table scrollable with header I want to make header non scrollable while Table rows will be scrollable how can i achieve that, table created pro-grammatically Here is my code

 <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="100dp"
        android:background="#FFFFFF" >

        <HorizontalScrollView
            android:layout_width="fill_parent"
            android:layout_height="450dp"
            android:background="#FFFFFF" >

            <TableLayout
                android:id="@+id/tblTrans"
                android:layout_width="450dp"
                android:layout_height="100dp"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="5dp"
                android:layout_marginTop="5dp" >
            </TableLayout>
        </HorizontalScrollView>
    </ScrollView>

Upvotes: 4

Views: 8239

Answers (1)

Anil Jadhav
Anil Jadhav

Reputation: 2158

If you wanted to scroll only data and not the headers then use two different tables . One for headers and other for all data.

Example code:

     <TableLayout
            android:id="@+id/tblHeaders"
            android:layout_width="450dp"
            android:layout_height="100dp"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="5dp" >
     </TableLayout>

  <ScrollView
    android:layout_width="fill_parent"
    android:layout_height="100dp"
    android:background="#FFFFFF" >



    <HorizontalScrollView
        android:layout_width="fill_parent"
        android:layout_height="450dp"
        android:background="#FFFFFF" >

        <TableLayout
            android:id="@+id/tblData"
            android:layout_width="450dp"
            android:layout_height="100dp"
            android:layout_marginLeft="5dp"
            android:layout_marginTop="0dp" >
        </TableLayout>
    </HorizontalScrollView>
</ScrollView>

Note: Adjust height and width of both tables as necessory.

Upvotes: 10

Related Questions