2011-01-27 22 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