2011-01-27 23 views
3

我有以下代碼是一個listview的基礎。表格中的複選框被textview推下屏幕

這個想法是有一個總是與屏幕右側對齊的複選框。如果它左邊的文字太長,我希望它被省略「......」或優雅地切斷。

只要文字很短,它就可以正常工作,但文本很長時不會。有什麼建議?

<?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和複選框的更好,並設置layout_width到0dip和使用Android: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/ 當我這樣做時,你推薦它的方式工作,但文本在下一行中被截斷。現在這不是一個大問題。這個例子很難顯示,因爲你必須在列表中有多個項目...... – 2011-01-27 18:21:23