Android关于TableLayout和省略号的问题

标签 android xml layout 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>

最佳答案

根据你想在哪一列设置上限,你需要使用

android:shrinkColumns=x 

在您的 TableLayout 中,其中 x 是您要省略的列的索引。

您可能还想将 TextView 上的 maxLines 也设置为 1。

关于Android关于TableLayout和省略号的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6381095/

相关文章:

android - 在 Android 中构建 iBeacon 广告时出现问题

java - 操作栏选项卡全部显示在一个 View 中,而不是可滚动

c++ - XML 中的 UTF 8 编码日文字符串

切换主题时 Delphi VCL 应用程序布局发生变化

android - 带有 com.google.android.material.textfield.TextInputLayout 的 boxStrokeColor 不起作用

javascript - 固定位置窗口滚动问题

android - 布局编辑器 : How to show layout in framelayout container?

Android服务器和客户端连接

java - spring - 从类路径加载 GenericXmlApplicationContext

ruby - 如何使用 Nokogiri 阅读器界面告知节点的行号?