2011-01-07 8 views
4

J'utilise TableLayout pour afficher les données. Le texte des TextViews de la colonne de droite sera défini lorsque l'activité appelle onCreate(). Maintenant, comme vous pouvez le voir dans l'image suivante, le texte de mon adresse peut être long et doit être encapsulé. J'ai donc réglé android:layout_width="wrap_content". mais il faut encore une largeur de la taille de l'écran pour envelopper les données. Comment puis-je surmonter ce problème?Android TableLayout question de largeur

alt text

Mon xml:

<?xml version="1.0" encoding="utf-8"?> 
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5px"> 
    <TableRow> 
     <TextView android:text="Job#" 
      android:paddingRight="5px" /> 
     <TextView android:id="@+id/DetailJobNo" /> 
    </TableRow> 
    <TableRow> 
     <TextView android:text="Address" 
      android:paddingRight="5px" /> 
     <TextView android:id="@+id/DetailAddress" 
      android:layout_width="wrap_content" 
      android:text="Address Address Address Address Address Address Address Address "/> 
    </TableRow> 
</TableLayout> 

Répondre

6

Ajout android:shrinkColumns="1" à TableLayout résout mon problème.

0

@Vikas, c'est bien que vous ayez résolu votre problème.

BUt Je recommande toujours d'utiliser HorizontalScrollView à des fins de sécurité. Si du moins quelques caractères ne sont pas visibles, la barre de défilement horizontale vous aidera à gérer cela. Texte XML:

<HorizontalScrollView android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="10dp" android:layout_marginBottom="10dp" > 

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:padding="5px"> 
    ...... 
    ...... 
    ADD YOUR ROWS 
</TableLayout>  
</HorizontalScrollView> 

Il est toujours préférable de prendre soin de l'inattendu.