4

I am currently developing an app and just ran some testing on ice cream sandwich and noticed some odd behavior when using the property android:ellipsize="end" in a textview. it is adding a [ character after the dots. This bug is driving me nuts and only appearing in ice cream sandwich. I saw a previous thread about this, but none of the fixes there helped. Any ideas, but report for android 4.0, maybe? My code below incase I am wronging ice cream sandwich somehow.

 <LinearLayout
     android:id="@+id/mainTitleLayout"
     android:layout_width="wrap_content"
     android:layout_height="fill_parent"
     android:layout_weight="0.36"
     android:orientation="horizontal"
     android:weightSum="1" >
<TextView
    android:id="@+id/mainTitle"
    android:layout_width="135dp"
    android:layout_height="wrap_content"
    android:layout_marginLeft="62dp"
    android:layout_marginTop="4dp"
    android:layout_weight="0.53"
    android:editable="false"
    android:ellipsize="end"
    android:gravity="center_vertical|center_horizontal"
    android:singleLine="true"
    android:textColor="#fff"
    android:textSize="26sp"
    android:textStyle="bold"
    android:width="125dp" >
</TextView>
</LinearLayout>

I set the text dynamically in code via

TextView title = (TextView) act.findViewById(R.id.mainTitle);
title.setTypeface(Utils.font);
title.setText(detailTitle);
Community
  • 1
  • 1
MikeIsrael
  • 2,871
  • 2
  • 22
  • 34
  • I've tested it in a LinearLayout with some random text but the text was truncated as expected. There's no other character after the 3 dots . Can you show us the text you put in TextView and how you put it in there? – Flo Jan 05 '12 at 09:35
  • Also with your LinearLayout around the TextView it works just fine. – Flo Jan 05 '12 at 09:38
  • this was causing it for me "NEW YORK SUNGLASSES" I am setting the text dynamically through code, so that might have something to do with it, if you run setText on the textfield it is still ok? – MikeIsrael Jan 05 '12 at 09:39
  • Yes the should be ok. Show the code where you set the text. – Flo Jan 05 '12 at 09:44
  • ok I updated the question and found the originating issue, the setTypeface to a different font seems to be causing the [ to appear. I changed the font and it was fine. But I don't get why this would only appear on ice cream sandwich – MikeIsrael Jan 05 '12 at 09:53
  • Ah great, at least you found the source of the problem. But yes that's indeed a very strange behavior. – Flo Jan 05 '12 at 09:53
  • yeah but finding the source doesn't really help me because I want to use that font package – MikeIsrael Jan 05 '12 at 10:04

3 Answers3

6

I think I know your problem. I have discovered this problem with my custom font that I set via setTypeface. The answer is found in the source code for Layout, which handles the drawing of TextViews to the screen. Take a look at the method 'ellipsize' at ling 1668. It appears to use a character, the 0-width space (U+FEFF), in addition to the ellipsis character. My guess is that your custom font does not include the 0-width space character, this causing the box to render. I have the same problem! The fix would necessitate altering the .ttf or .otf file to include the 0-width space character. Hope this helps!

icecreamman
  • 611
  • 1
  • 5
  • 19
  • I have same problem but i don't know How do we alert the .ttf or .otf file and include the 0-width space character. please help me – naresh Jul 12 '13 at 09:45
1

I had a similar problem using a custom font in a TextView, actually in 1.6. In my case, I replaced the standard TextView with the version in this link:

android ellipsize multiline textview

and the extra characters went away.

Community
  • 1
  • 1
Sara
  • 11
  • 1
0

If I were you, I would try minLines and maxlines inside TextView declaration, this way:

android:minLines="1"
android:maxLines="1"

instead of android:singleLine="true". I had a similar problem, that emerged only when using android 4. I solved this way, but I didn't change the font via setTypeface.

Shine
  • 3,788
  • 1
  • 36
  • 59