Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Italic TextView with wrap_contents seems to clip the text at right edge

<TextView android:id="@+id/prodLbl"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_centerHorizontal="true"     android:layout_centerVertical="true"     android:textColor="#FFFFFF"     android:textSize="30dip"     android:textStyle="italic"     android:text="Magnifico"     /> 

Seems to clip few pixels from the rightmost character, at least on 480x800 emulator or Nexus One.

To me it looks like a bug, but I'm just an Android beginner. I tried to add margins to left and right, but it still kept on clipping. In the end my hack around it was to add a single space on both sides of the text. Any other solutions?

like image 203
Grego Avatar asked Dec 04 '10 13:12

Grego


People also ask

How do I center a TextView layout?

When you have a LinearLayout view, you can center the TextView widget by setting the layout_width and layout_height attributes of the TextView to match_parent and the gravity attribute to center . You can also center multiple TextView widgets by using the layout_weight attribute.


2 Answers

android:layout_width="wrap_content" , gives you a rectangle for wrapped content rendering. All will work well for normal text (non-italic).

Once you have italic text enabled, the wrapped text will try to fit into the rectangle and hence the rightmost character will be cut off unless its un-cut-able (such as ., ), 1, etc.)

Solution as suggested is to have a space at the end of the text (or anything better ??)

PS: This applies to android:gravity="right" too because the text will be pushed to the rightmost. If we have italic text, we face the same problem.

like image 82
danfelabs Avatar answered Sep 21 '22 19:09

danfelabs


You could also use the Unicode no-break space character (\u00A0).

like image 33
Sam Avatar answered Sep 20 '22 19:09

Sam