【问题标题】:checkboxes in tablerow pushed off screen by textviewtablerow 中的复选框被 textview 推离屏幕
【发布时间】:2011-06-16 16:30:03
【问题描述】:

我有以下代码是列表视图的基础。

这个想法是有一个始终与屏幕右侧对齐的复选框。如果左边的文字太长,我希望它是椭圆形的“...”或优雅地切断。

只要文本很短,它就可以正常工作,但当文本很长时就不行。有什么建议吗?

<?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>

【问题讨论】:

    标签: android listview checkbox android-layout


    【解决方案1】:

    不太清楚为什么要使用 TableRow,但最好将 TextView 和 Checkbox 包装在线性布局中,并将 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>
    

    【讨论】:

    • 谢谢,这似乎运作良好。我使用表格布局的原因是因为我真正想做的就是拥有一个带有右对齐复选框的列表,然后 Google 将我带到了这个示例:huuah.com/using-tablelayout-on-android 当我按照您推荐的方式进行操作时,它可以工作,但文本是在下一行切断。这暂时不是什么大问题。在此示例中很难显示,因为您必须在列表中有多个项目...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-14
    • 1970-01-01
    • 2011-10-26
    相关资源
    最近更新 更多