9

I have some problem with standard android ellipsize mechanism.

My textview xml layout is next:

<TextView
        android:id="@+id/something"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/message_test_text"
        android:lines="2"
        android:ellipsize="end"
        android:textColor="@drawable/dialogs_text_selector"
 />

Then in code I'm setting Helvetica typeface to this field. And then, in the end of second line I see broken symbol after dots:

Broken symbol

Because it used in list, I see a list of squares.

Can I remove it without tons of code?

Thank you!

Roman Truba
  • 4,401
  • 3
  • 35
  • 60
  • Does it work fine with other fonts? – Ron Jun 24 '12 at 13:45
  • could be the problem wit font file.. try using a different copy of the font file.. – Ron Jun 24 '12 at 16:30
  • *"Then in code I'm setting Helvetica typeface to this field"* Hopefully you have paid for a license for this font. Otherwise, please do not distribute it. *"And then, in the end of second line I see broken symbol after dots:"* This has been covered before, such as: https://stackoverflow.com/questions/5794488/android-how-to-get-rid-of-question-mark-at-end-of-ellipsize – CommonsWare Jun 28 '12 at 14:11

2 Answers2

6

There is a issue logged here. Many people have some or the other problem when using TextView with ellipsize in a ListView. There are many workarounds that suggest changing the textview to single line, but you cant use that.

Try setting the android:maxLines="2" attribute.

Update:

Use TextUtils.ellipsize API to manually ellipsize the string before setting it to the textview. See whether the ellipsized string returned by this API contains the square char at the end.

Usage sample code:

TextPaint tp = new TextPaint();
tp.setTextSize(float textSize);
tp.setTypeface(Typeface typeface);
Charsequence elipText;
elipText = TextUtils.ellipsize ( text, tp, avail, TextUtils.TruncateAt.END);
textview.setText(elipText);
Ron
  • 24,175
  • 8
  • 56
  • 97
4

The problem here I don't think it was your code. The problem is your .tff file which is missing the ellipsize character, hence the square is displayed. Your font was not... let's say mobile optimized.

Ovidiu Latcu
  • 71,607
  • 15
  • 76
  • 84