我在TableLayout的列中有一个TextView.如果TextView的文本比列可以容纳的长,我希望TextView截断和椭圆化,但它只是拉伸列并破坏我的布局.我发现TextView截断的建议都没有用,我假设这是由于表.有什么建议?
<?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>
Run Code Online (Sandbox Code Playgroud)
*编辑:表格代码:
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));
Run Code Online (Sandbox Code Playgroud)
Nic*_* A. 11
您需要设置都 shrinkColumns和stretchColumns含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>
Run Code Online (Sandbox Code Playgroud)