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>
In android, You can scroll the elements or views in both vertical and horizontal directions. To scroll in Vertical we simply use ScrollView as we shown in the previous code of this article and to scroll in horizontal direction we need to use HorizontalScrollview.
In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. 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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With