4

I am using following code to create a TableLayout which is scrollable horizontally:

      <?xml version="1.0" encoding="utf-8"?>
      <HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
           android:layout_width="fill_parent"
           android:layout_height="fill_parent"
           android:minWidth="200dp"
           android:scrollbars="none">

       <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"            android:id="@+id/maintable2"
                android:layout_width="fill_parent"                  
                android:layout_height="fill_parent"                     
                android:stretchColumns="*"                      
                android:background ="#dddddd"           
                android:scrollbars="none"   >       
       </TableLayout>               
   </HorizontalScrollView>

I need the columns in the TableLayout to at least fill the screen (i.e. if there is only one column, the borders of that columns should stretch over the whole screen, if there are two columns, the borders of both columns should fill the screen etc.).

How can I do that?

inazaruk
  • 74,247
  • 24
  • 188
  • 156
deimos1988
  • 5,896
  • 7
  • 41
  • 57

2 Answers2

12

I had the same problem. I solved it by adding android:fillViewport="true" to the HorizontalScrollView.

Aziz Shaikh
  • 16,245
  • 11
  • 62
  • 79
guspodes
  • 121
  • 1
  • 4
-1

Showing three columns with equal size next to each other

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TableLayout
    android:layout_weight="1"
    android:layout_width="fill_parent"                  
    android:layout_height="fill_parent"
    android:background ="#dddddd"
    />
<TableLayout
    android:layout_weight="1"
    android:layout_width="fill_parent"                  
    android:layout_height="fill_parent"
    android:background="#ffffff"
    />
<TableLayout
    android:layout_weight="1"
    android:layout_width="fill_parent"                  
    android:layout_height="fill_parent"
    android:background ="#dddddd"
    />

BenjaminButton
  • 334
  • 1
  • 7
  • 19
  • 2
    Benjamin, your answer is seriously flawed. Not only it does not use HorizontalScrollView, but it also uses three separate TableLayouts each serving as column. That does not make sense. There should be one TableLayout with TableRow(s) containing views as contents of the columns. – compostus May 17 '11 at 21:08