简体   繁体   English

Android有关TableLayout和省略号的问题

[英]Android question about TableLayout and ellipsis

I'm having a problem with my TableLayout. 我的TableLayout出现问题。 It consists of two columns and multiple rows. 它由两列和多行组成。 When the TextView of the second column contains text of a longer width, then it pushes the TextView's in that column (in the below rows) off of the screen (to the right). 当第二列的TextView包含较长宽度的文本时,它将把该列(下一行)中的TextView移出屏幕(向右)。 Instead, I want it to keep the text to the left and have it cap the text at the end with an ellipsis. 相反,我希望它将文本保留在左侧,并在其末尾加一个省略号。 Can anyone see what's wrong with my XML? 谁能看到我的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>

Depending on which column you want to put the cap on, you need to use 根据要设置上限的列,您需要使用

android:shrinkColumns=x 

in your TableLayout where x is the index of the column you want to ellipsize. 在您的TableLayout ,其中x是您要椭圆化的列的索引。

You probably also want to set the maxLines on the TextView to 1 as well. 您可能还希望将TextView上的maxLines也设置为1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM