gpt4 book ai didi

Android如何去掉椭圆末尾的问号

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:51:49 27 4
gpt4 key购买 nike

我定义了以下 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"/>

正如预期的那样,如果文本太长,文本将被截断并替换为“...”。但是在这三个点的末尾出现了一个被正方形包围的问号。

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

谢谢!

最佳答案

引自 one of my books :

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.

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.

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.

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).

关于Android如何去掉椭圆末尾的问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5794488/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com