Introduction to Android ellipsize

  • 2020-05-05 11:52:00
  • OfStack

When using TextView, the ellipsis will be displayed automatically after the length is long. There is native support in android, which is defined as
 
<TextView ... 
android:ellipsize="end" 
android:singleLine="true"/> 

At first glance it can be used, but on closer inspection it is found in the ellipsis... There is a box in the back, similar to the kind of characters that appear garbled, why is this?

ellipsize in android was dealing with strings. If it found that the string was too long, it would replace the last character with... , not three dots, but an ellipsis built into the font. No matter what font you use, you need to support this ellipsis to display correctly. The font used by APP is Mercedes, which supports ellipsis display. There is no problem here. The problem is that when android processes ellipsize, it replaces a character with... , replace the remaining truncated characters with the Unicode character "ZERO WIDTH NO-BREAK SPACE" (U+FEFF), which is not displayed on the screen, but is still part of the string.

The original problem is that the Mercedes font does not support the display of this special character U+FEFF, so the garble occurs. The solution is simple: edit the font file and set the width of U+FEFF to 0.

Related articles: