2011-01-27 12 views
3

私はリストビューの基礎となる次のコードを持っています。tablerowのチェックボックスは、テキストビューで画面にプッシュオフ

アイデアは、常に画面の右側に揃えられたチェックボックスを持つことです。それの左側にあるテキストが長すぎると、私はそれを省略記号 "..."にするか、または優雅に切り捨てたいと思います。

テキストは短いが、テキストが長い場合と同じように動作しません。何かアドバイス?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

<TableLayout android:id="@+id/TableLayout01" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:stretchColumns="0" 
> 

    <TableRow 
     android:id="@+id/TableRow01" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
    > 

     <TextView android:id="@+id/name" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dip" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:text="This is a very very long title 12345678"  
     /> 

     <CheckBox android:id="@+id/checkbox" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content"   
     /> 

    </TableRow> 
</TableLayout> 

</LinearLayout> 

答えて

1

なぜあなたはのTableRowを使用しているが、あなたはリニアレイアウトでのTextViewとチェックボックスを包むのより良いとAndroidを0dip、使用するlayout_width設定されすぎてわからない:layout_weightをのTextViewとの両方の比率を設定しますチェックボックス。

例:うまく動作するようです

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <TextView android:id="@+id/TextView01" android:layout_height="wrap_content" 
     android:layout_width="0dip" android:layout_weight="3" android:text="TextView"></TextView> 
    <CheckBox android:id="@+id/CheckBox01" android:layout_height="wrap_content" 
     android:layout_width="0dip" android:layout_weight="1"></CheckBox> 
</LinearLayout> 
+0

感謝。私がテーブルレイアウトを使用した理由は、私が本当にやりたかったのは、右揃えのチェックボックスのリストを持っていて、Googleがこの例に私を導いたからです:http://huuah.com/using-tablelayout-on-android/ 私はあなたがそれを推奨しているようにするが、テキストは次の行で途切れる。これは今のところ大したことではありません。あなたがリストに複数のアイテムを持っていなければならないので、この例に示すのは難しいです... –

関連する問題