Android关于TableLayout和省略号的问题

lit*_*leK 3 xml layout android tablelayout

我的 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>
Run Code Online (Sandbox Code Playgroud)

Gle*_*ger 5

根据您想要设置上限的列,您需要使用

android:shrinkColumns=x 
Run Code Online (Sandbox Code Playgroud)

其中TableLayoutx 是要省略的列的索引。

您可能还想将 maxLines 设置为TextView1。