机器人如何获得在ellipsize结束摆脱问号问号、机器人、如何获得、结束

2023-09-05 09:07:36 作者:笙墨时殊

我定义以下TextView的:

I've defined the following TextView:

    <TextView
    android:id="@+id/textview_id"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="left"
    android:layout_alignParentTop="true"
    android:layout_marginRight="25dip"
    android:ellipsize="end"/>

和预期的文本被切断,如果它太长,取而代之的是...。但在这三个点的结尾出现一个问号被正方形包围。

And as expected the text is cut off if it's too long and replaced by "...". But at the end of the three points appears a question mark surrounded by a square.

我怎样才能摆脱掉这个问号?

How can I get rid off this question mark?

谢谢!

推荐答案

从引用自己我的书之一:

Android的的TextView 类有内置的能力ellipsize的文字,   截断它并添加一个省略号,如果文本比现有的长   空间。您可以通过 Android的使用:ellipsize 属性,例如。   这工作还算不错,至少对单行文本。

Android's TextView class has the built-in ability to "ellipsize" text, truncating it and adding an ellipsis if the text is longer than the available space. You can use this via the android:ellipsize attribute, for example. This works fairly well, at least for single-line text.

这是Android使用省略号不是三个时期。相反,它使用了一个实际的   省略号字符,其中所述三个点被包含在一个字形。   因此,你使用,你还可以使用ellipsizing功能的任何字体将   需要省略号字形。

The ellipsis that Android uses is not three periods. Rather it uses an actual ellipsis character, where the three dots are contained in a single glyph. Hence, any font that you use that you also use the "ellipsizing" feature will need the ellipsis glyph.

除此之外,虽然Android的垫出来的字符串被渲染的导通   屏幕上,使得该长度(字符数)是相同的前,后   ellipsizing。为了使这项工作,机器人代替一个字符用   省略号,并取代所有其他的删除的字符与UNI code   字符ZERO WIDTH NO-BREAK SPACE( U + FEFF )。这意味着   额外字符的省略号后不占用任何可见的空间   屏幕上,但它们可以是字符串的一部分。

Beyond that, though, Android pads out the string that gets rendered on- screen, such that the length (in characters) is the same before and after "ellipsizing". To make this work, Android replaces one character with the ellipsis, and replaces all other removed characters with the Unicode character 'ZERO WIDTH NO-BREAK SPACE' (U+FEFF). This means the "extra" characters after the ellipsis do not take up any visible space on screen, yet they can be part of the string.

不过,这意味着你使用的的TextView 小部件的任何自定义字体,   您使用安卓ellipsize 也必须支持这个特殊的Uni code   字符。不是所有的字体做的,你会得到在屏幕上的文物   重新您缩短串presentation如果您的字体缺少这个人物   (例如,流氓X的出现在该行的末尾)。

However, this means any custom fonts you use for TextView widgets that you use with android:ellipsize must also support this special Unicode character. Not all fonts do, and you will get artifacts in the on-screen representation of your shortened strings if your font lacks this character (e.g., rogue X's appear at the end of the line).