Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to scroll table layout in horizontal and vertical in android

Tags:

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> 
like image 649
user1811379 Avatar asked May 18 '13 10:05

user1811379


People also ask

How to get horizontal scroll view in Android?

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.

Can scroll vertically Android?

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.


1 Answers

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.

like image 174
Emil Adz Avatar answered Sep 19 '22 18:09

Emil Adz