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?


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.


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


I added " \" to end of all strings in my strings.xml. \ is the escape character, so this way I could come over the issue, but this solution is nasty. Hope this helps.


Just add an extra space to the end of the text. In XML, you will have to add \u0020 to the end as otherwise XML ignores whitespace at the beginning/end by default.


Found another solution (tested on 4.1.2 and 4.3 while using wrap_content). If you extend TextView or EditText class you can override onMeasure method this way:

@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    final int measuredWidth = getMeasuredWidth();
    final float tenPercentOfMeasuredWidth = measuredWidth * 0.1f;
    final int newWidth = measuredWidth + (int) tenPercentOfMeasuredWidth;

    setMeasuredDimension(newWidth, getMeasuredHeight());
}