TableLayout в HorizontalScrollView - PullRequest
4 голосов
/ 18 мая 2011

Я использую следующий код для создания TableLayout, который можно прокручивать по горизонтали:

      <?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>

Мне нужны столбцы в TableLayout, чтобы хотя бы заполнить экран (т. Е. Если есть только один столбец, границы этих столбцов должны растягиваться на весь экран, если есть два столбца, границы обоих столбцов должен заполнить экран и т. д.).

Как я могу это сделать?

Ответы [ 2 ]

10 голосов
/ 11 ноября 2011

У меня была такая же проблема. Я решил это, добавив android:fillViewport="true" к HorizontalScrollView.

0 голосов
/ 18 мая 2011

Отображение трех столбцов одинакового размера рядом друг с другом

<?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"
    />

...