I have a TextView in a column of my TableLayout. I would like the TextView to truncate and ellipsize if its text is longer than the column can accommodate, but it just stretches the column and destroys my layout. None of the suggestions for TextView truncating I have found have worked, I'm assuming this is due to the Table. Any suggestions?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</TextView>
<RelativeLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/Icon"
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
<TextView
android:id="@+id/Value"
android:layout_toRightOf="@id/Icon"
android:text="very long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long string"
android:inputType="text"
android:maxLines="1"
android:ellipsize="end"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</TextView>
</RelativeLayout>
*EDIT: Code for the table:
int fiveDip = convToDip(5, getContext());
Table table = new TableLayout(getContext());
table.setPadding(fiveDip, fiveDip, fiveDip, fiveDip);
table .setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.FILL_PARENT));
You need to set both shrinkColumns and stretchColumns on the column containing the TextView:
<?xml version="1.0" encoding="utf-8"?>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:shrinkColumns="1"
android:stretchColumns="1">
<TableRow>
<View
android:background="#f00"
android:layout_height="fill_parent"
android:layout_width="40dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="18sp"
android:textColor="#fff"
android:ellipsize="end"
android:singleLine="true"
android:text="Example text that is very loooooooooooooooooooooooooooooooooooooooooooooong" />
<View
android:background="#00f"
android:layout_height="fill_parent"
android:layout_width="40dp" />
</TableRow>
</TableLayout>
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