флажки в tablerow отодвинуты от экрана при просмотре текста - PullRequest
3 голосов
/ 27 января 2011

У меня есть следующий код, который является основой для просмотра списка.

Идея состоит в том, чтобы иметь флажок, который всегда выровнен по правому краю экрана. Если текст слева от него будет слишком длинным, я бы хотел, чтобы он был "..." или изящно обрезан.

Работает нормально, если текст короткий, а не такой, как текст длинный. Любой совет?

<?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 Ответ

1 голос
/ 27 января 2011

Не совсем уверен, почему вы используете 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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...