I have the following code that is a foundation for a listview.
The idea is to have a checkbox that is always aligned to the right of the screen. Should the text to the left of it be too long I would like it to be ellipsized "..." or cut off gracefully.
It works fine as long as the text is short but not as is when the text is long. Any advice?
<?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>
Not too sure why you are using a TableRow but you are better of wrapping the TextView and Checkbox in a Linear layout and set layout_width to 0dip and use android:layout_weight to set the ratios of both the textview 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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With