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

前端 未结 13 1262
孤独总比滥情好
孤独总比滥情好 2020-12-24 10:22


        
相关标签:
13条回答
  • 2020-12-24 10:56

    A proper and clean solution:

    Use an italic custom font instead of setting textStyle='italic' For example:

    <android.support.v7.widget.AppCompatTextView
                android:text="yolO"
                app:fontFamily="@font/roboto_italic"/>
    

    I haven't tried it on regular TextView but from my observations, the problem is with textStyle='italic'.

    Works without any hack!

    Here's a proof of blaming textStyle attribute:

    I made a custom fontFamily and defined typeface for normal, bold and italic

    res/font/app_font_family.xml

    <font-family xmlns:app="http://schemas.android.com/apk/res-auto">
        <font app:fontStyle="normal" app:fontWeight="400" app:font="@font/roboto_regular"/>
        <font app:fontStyle="italic" app:fontWeight="400" app:font="@font/roboto_italic" />
        <font app:fontStyle="normal" app:fontWeight="700" app:font="@font/roboto_medium"/>
    </font-family>
    

    Now when I use this fontFamily and apply textStyle='italic', the rightmost character is still clipped.

    <android.support.v7.widget.AppCompatTextView
                android:text="yolO"
                app:fontFamily="@font/app_font_family"
                android:textStyle='italic' />
    

    This is on Api 23 with support library 28.0.0 and Android Studio 3.2

    0 讨论(0)
  • 2020-12-24 10:56

    I also had the same issue and used a non-breaking space entity via HTML:

    textView.setText("Magnifico" + Html.fromHtml("&nbsp;");
    
    0 讨论(0)
  • 2020-12-24 10:57

    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.

    0 讨论(0)
  • 2020-12-24 11:05

    This applies to fixed-width TextViews also, not just "wrap_content". I'm not sure if the issue is version-specific as some commenters have alluded to. I see the issue on all Honeycomb versions. From what I've seen the issue does not go away by setting margin, padding, using a fixed-width, or a true-italic custom typeface.

    0 讨论(0)
  • 2020-12-24 11:06

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

    0 讨论(0)
  • 2020-12-24 11:06

    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.

    0 讨论(0)
提交回复
热议问题