Horizontal scrolling in table

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Horizontal scrolling in table

Postby gecu_121 » Fri Jul 31, 2009 6:42 am

hi...
I am developing an application which includes a table. this table scrolls both side means horizontally and vertically. I am easily able to scroll it vertically by keeping my table layout in ScrollView. But it does not support horizontal scroll.
I tried to achieve horizontal scrolling by the scrollBy method. But problem is after scrolling upto 4 columns, rest of the columns diapprears. The source code and corresponding xml is attached below. Could anybody tell me the solution of this problem?[font=Arial] [/font]

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. package com.pack.entrypoint;
  2.  
  3. import android.app.Activity;
  4.  
  5. import android.os.Bundle;
  6.  
  7. import android.view.KeyEvent;
  8.  
  9. import android.view.View;
  10.  
  11. import android.widget.TableLayout;
  12.  
  13. import android.widget.TableRow;
  14.  
  15.  
  16.  
  17. public class MainActivity extends Activity {
  18.  
  19.        
  20.  
  21.         TableLayout tableLayout = null;
  22.  
  23.        
  24.  
  25.     /** Called when the activity is first created. */
  26.  
  27.     @Override
  28.  
  29.     public void onCreate(Bundle savedInstanceState) {
  30.  
  31.         super.onCreate(savedInstanceState);
  32.  
  33.         setContentView(R.layout.table_header);
  34.  
  35.         tableLayout = (TableLayout)findViewById(R.id.header_table_layout);
  36.  
  37.        tableLayout.setClipChildren(false);
  38.  
  39.     }
  40.  
  41.    
  42.  
  43.         @Override
  44.  
  45.         public boolean onKeyDown(int keyCode, KeyEvent event) {
  46.  
  47.                 // TODO Auto-generated method stub
  48.  
  49.                 switch(keyCode){
  50.  
  51.                 case KeyEvent.KEYCODE_DPAD_RIGHT:
  52.  
  53.                         tableLayout.scrollBy(160, 0);
  54.  
  55.                         break;
  56.  
  57.                 case KeyEvent.KEYCODE_DPAD_LEFT:
  58.  
  59.                         tableLayout.scrollBy(-160, 0);
  60.  
  61.                         break;
  62.  
  63.                 }
  64.  
  65.                 return true;
  66.  
  67.         }
  68.  
  69.    
  70.  
  71.    
  72.  
  73. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4




and xml


Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2.  
  3. <ScrollView android:id="@+id/table_scrollview"
  4.  
  5.         android:layout_width="fill_parent" android:layout_height="fill_parent"
  6.  
  7.         android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
  8.  
  9. <TableLayout android:id="@+id/header_table_layout"
  10.  
  11.         android:layout_width="fill_parent" android:layout_height="fill_parent"
  12.  
  13.         android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android">
  14.  
  15.         <TableRow android:id="@+id/header_row" android:layout_width="fill_parent"
  16.  
  17.                 android:layout_height="wrap_content" android:orientation="horizontal">
  18.  
  19.                 <TextView android:id="@+id/column1"
  20.  
  21.                         android:layout_width="160px" android:layout_height="wrap_content"
  22.  
  23.                         android:text="Column 1" android:gravity="center">
  24.  
  25.                 </TextView>
  26.  
  27.                 <TextView android:id="@+id/column2"
  28.  
  29.                         android:layout_width="160px" android:layout_height="wrap_content"
  30.  
  31.                         android:text="Column 2" android:gravity="center">
  32.  
  33.                 </TextView>
  34.  
  35.                 <TextView android:id="@+id/column3"
  36.  
  37.                         android:layout_width="160px" android:layout_height="wrap_content"
  38.  
  39.                         android:text="Column 3" android:gravity="center">
  40.  
  41.                 </TextView>
  42.  
  43.                 <TextView android:id="@+id/column4"
  44.  
  45.                         android:layout_width="160px" android:layout_height="wrap_content"
  46.  
  47.                         android:text="Column 4" android:gravity="center">
  48.  
  49.                 </TextView>
  50.  
  51.                 <TextView android:id="@+id/column5" android:layout_width="160px"
  52.  
  53.                         android:layout_height="wrap_content" android:text="Column 5"
  54.  
  55.                         android:gravity="center">
  56.  
  57.                 </TextView>
  58.  
  59.                 <TextView android:id="@+id/column6" android:layout_width="160px"
  60.  
  61.                         android:layout_height="wrap_content" android:text="Column 6"
  62.  
  63.                         android:gravity="center">
  64.  
  65.                 </TextView>
  66.  
  67.                 <TextView android:id="@+id/column7"
  68.  
  69.                         android:layout_width="160px" android:layout_height="wrap_content"
  70.  
  71.                         android:text="Column 7" android:gravity="center">
  72.  
  73.                 </TextView>
  74.  
  75.                 <TextView android:id="@+id/column8"
  76.  
  77.                         android:layout_width="160px" android:layout_height="wrap_content"
  78.  
  79.                         android:text="Column 8" android:gravity="center">
  80.  
  81.                 </TextView>
  82.  
  83.                 <TextView android:id="@+id/column9"
  84.  
  85.                         android:layout_width="160px" android:layout_height="wrap_content"
  86.  
  87.                         android:text="Column 9" android:gravity="center">
  88.  
  89.                 </TextView>
  90.  
  91.         </TableRow>
  92.  
  93. </TableLayout>
  94.  
  95. </ScrollView>
Parsed in 0.009 seconds, using GeSHi 1.0.8.4
gecu_121
Junior Developer
Junior Developer
 
Posts: 17
Joined: Thu Jul 30, 2009 2:39 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Google [Bot] and 4 guests