关于TableLayout和省略号的Android问题



我的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。

最新更新