我的 TableLayout 有问题。它由两列和多行组成。当第二列的 TextView 包含较长宽度的文本时,它将将该列(在下面的行中)中的 TextView 推离屏幕(向右)。相反,我希望它将文本保持在左侧,并在末尾用省略号将文本加上。任何人都可以看到我的 XML 有什么问题吗?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#4096cc" >
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/roundedshape"
android:layout_margin="5dp"
android:stretchColumns="1">
<TableRow>
<TextView
android:layout_column="1"
android:text="Server Name"
android:textStyle="bold"
android:padding="10dip" />
<TextView
android:id="@+id/txtServerName"
android:text=""
android:gravity="right"
android:ellipsize="end"
android:padding="10dip" />
</TableRow>
<View
android:layout_height="2dip"
android:background="#FF909090" />
<TableRow>
<TextView
android:layout_column="1"
android:text="Status"
android:textStyle="bold"
android:padding="10dip" />
<ImageView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:padding="10dip"
android:src="@drawable/icon" />
</TableRow>
.
.
.
</TableLayout>
</LinearLayout>
最佳答案
根据你想在哪一列设置上限,你需要使用
android:shrinkColumns=x
在您的 TableLayout
中,其中 x 是您要省略的列的索引。
您可能还想将 TextView
上的 maxLines 也设置为 1。
关于Android关于TableLayout和省略号的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6381095/