I\'ve defined the following TextView:
To quote myself from 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 theandroid: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 withandroid: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).
Had the same problem. Somebody with FontForge knowledge fixed the U+FEFF in my custom fonts and now they work well. Here is how he described what he did:
"I'm not good with Fontforge, so I cheated. Basically, opened the font in Fontforge, selected the space character, ctrl+c for copy, then selected FEFF, ctrl+v for paste. Then menu Metrics->Set Width and set to zero. Then File->Generate Fonts."