我的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>
*编辑:表格代码:
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));
答案 0 :(得分:11)
您需要在包含TextView的列上设置 {/ b> shrinkColumns
和stretchColumns
:
<?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>
答案 1 :(得分:0)
您的xml和代码似乎与您所述的问题无关。不过,您是否尝试过为TextView执行android:singleLine="true"
。对于Marquee,请参阅Android automatic horizontally scrolling TextView
此外,您可以使用TableLayout
打包ScrollView
以启用滚动功能。