Flags in tablerow are pushed out of the screen by text viewing

I have the following code, which is the basis for the list.

The idea is to have a checkbox that always aligns to the right of the screen. If the text to the left of it is too long, I would like it to be elliptical "..." or cut gracefully.

It works fine while the text is short, but not the same as the text is long. Any tips?

<?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>
+3
source share
1 answer

Not too sure why you are using TableRow, but you better wrap the TextView and Checkbox in a linear layout and set layout_width to 0dip and use android: layout_weight to set the relationship of both the text field and the checkbox.

eg:

<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>
+1
source

Source: https://habr.com/ru/post/1788247/


All Articles