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

标签 android user-interface textview

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

相关文章:

jQuery UI Accordion 禁用选项卡

c# - 向 ComboBox 添加数据(未绑定(bind)数据)

android - 我怎样才能在android studio上实现代码?

java - 程序与 CountDownTimer 配合得很好,直到还剩 3 秒,然后它调用两次

android - 在 AsyncTask 上调用 execute() 不会调用 doInBackground()

java - Google TV - 效率设计是否与手机/平板电脑一样重要?

android - 从内存下载并安装应用程序 (apk) - 无需 SD 卡

CSS - Safari 中缺少下拉菜单

android - 我正在尝试为空 ListView 制作一个 TextView,但我无法从 Activity 中获取 ListView

android - 从 ReceiverRestrictedContext 获取应用程序,就好像使用了 getApplication(不是 getApplicationContext)