【问题标题】:Ellipsize not working correctly in a TextView in a TableLayoutEllipsize 在 TableLayout 的 TextView 中无法正常工作
【发布时间】:2012-04-21 06:27:04
【问题描述】:

我有一个类似这样的多行表:

<TableRow
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="text"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:textSize="12sp"
        android:layout_gravity="right|center_vertical"
        android:layout_margin="4dip" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="some text"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="13sp"
        android:textStyle="bold"
        android:layout_gravity="left|center_vertical"
        android:layout_margin="4dip"
        android:ellipsize="end"
        android:lines="1"
        android:scrollHorizontally="true"
        android:layout_weight="1" />

    <ImageView
        android:src="@drawable/disclosure_indicator"
        android:contentDescription="@string/emptyString"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:scaleType="fitXY" />

</TableRow>

但如果文本视图中的任何行比剩余空间宽,第二个文本视图的最后一个“单词”将替换为“...”。

所以使用类似的东西:

"Some sort string"
"Some string that is a little bit longer"
"Singleword"

表格将呈现如下:

text | Some short...                       | >
text | Some string that is a little bit... | >
text |                                     | >

当明显有足够的空间来显示第一行的整个字符串时。 我怎样才能得到它,以便截断/省略对每一行都正确工作?

【问题讨论】:

标签: android textview tablelayout


【解决方案1】:

@MarSara9 更改第二个文本视图的布局重力。此解决方案适用于您的示例代码:

android:layout_gravity="center_vertical"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-30
    • 2012-12-19
    • 2021-12-03
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 2014-02-07
    相关资源
    最近更新 更多