2011-05-17 8 views
3

J'utilise le code suivant pour créer un TableLayout qui est scrollable horizontalement:TableLayout au sein HorizontalScrollView

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

J'ai besoin des colonnes dans le TableLayout au moins remplir l'écran (s'il n'y a qu'une seule colonne, la les bordures de ces colonnes doivent s'étendre sur tout l'écran, s'il y a deux colonnes, les bordures des deux colonnes doivent remplir l'écran, etc.).

Comment puis-je faire cela?

+0

Bien 'android: stretchColumns =" ​​* "' devrait faire exactement cela. Quel est le problème? – compostus

Répondre

-1

Affichage trois colonnes avec une taille égale à côté de l'autre

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

+2

Benjamin, votre réponse est sérieusement erronée. Non seulement il n'utilise pas HorizontalScrollView, mais il utilise également trois TableLayouts distincts servant chacun de colonne. Ça n'a pas de sens. Il doit y avoir un TableLayout avec TableRow (s) contenant des vues en tant que contenu des colonnes. – compostus

10

J'ai eu le même problème. Je l'ai résolu en ajoutant android:fillViewport="true" au HorizontalScrollView.

+0

Merci l'homme, cela résout exactement mon problème. –