2011-04-20 5 views
1

J'ai un TextView dans une colonne de ma TableLayout. Je voudrais que TextView tronque et ellipse si son texte est plus long que la colonne ne peut le faire, mais il étire juste la colonne et détruit ma disposition. Aucune des suggestions pour Troncature TextView que j'ai trouvé ont fonctionné, je suppose que cela est dû à la Table. Aucune suggestion?Android: comment tronquer TextView dans TableLayout?

<?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="wrap_content"> 
    <TextView 
     android:id="@+id/label" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
    </TextView> 
    <RelativeLayout 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
     <ImageView 
      android:id="@+id/Icon" 
      android:src="@drawable/icon" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
     </ImageView> 
     <TextView 
      android:id="@+id/Value" 
      android:layout_toRightOf="@id/Icon" 
      android:text="very long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long string" 
      android:inputType="text" 
      android:maxLines="1" 
      android:ellipsize="end" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"> 
     </TextView> 
    </RelativeLayout> 

* EDIT: Code de la table:

int fiveDip = convToDip(5, getContext()); 

Table table = new TableLayout(getContext()); 
table.setPadding(fiveDip, fiveDip, fiveDip, fiveDip); 
table .setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.FILL_PARENT)); 
+0

Pouvez-vous fournir votre TableLayout xml? – Joe

+0

@Joe. Je le définis dans le code, j'ai ajouté le code comme un edit à ma question. – ab11

Répondre

0

Votre xml et le code semble sans rapport avec le problème que vous avez dit. Néanmoins, avez-vous essayé de faire android:singleLine="true" pour votre TextView. Pour Marquee, voir Android automatic horizontally scrolling TextView

De plus, vous pouvez envelopper votre TableLayout avec un ScrollView pour activer le défilement.

+0

J'ai essayé en ajoutant simplement singleLine = "true", puis en utilisant votre code pour la sélection. Ni travaillé. A préférerait tronquer, que d'envelopper avec une scrollview. – ab11

11

Vous devez définir foisshrinkColumns et stretchColumns sur la colonne contenant le TextView:

<?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="40dp" 
    android:shrinkColumns="1" 
    android:stretchColumns="1">  
     <TableRow> 
      <View 
       android:background="#f00" 
       android:layout_height="fill_parent" 
       android:layout_width="40dp" /> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:textSize="18sp" 
       android:textColor="#fff" 
       android:ellipsize="end" 
       android:singleLine="true" 
       android:text="Example text that is very loooooooooooooooooooooooooooooooooooooooooooooong" /> 

      <View 
       android:background="#00f" 
       android:layout_height="fill_parent" 
       android:layout_width="40dp" /> 
     </TableRow> 

</TableLayout> 
+0

C'est là où je me suis trompé aussi, vous devez lui dire quels index de la colonne devraient rétrécir et croître. –