textview cutting off a letter in android

前端 未结 11 2344
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-02-18 12:56

\"http://dl.dropbox.com/u/24856/Screenshots/android/cutoff.png\"

this is a screen shot from my android. the text is

相关标签:
11条回答
  • 2021-02-18 13:18

    You can use .

    android:layout_width="fill_parent"
    

    istead of

    android:layout_width="wrap_content"
    
    0 讨论(0)
  • 2021-02-18 13:18

    I suspect the issue would not occur if you were not using italic text. I'd test that out first, and if using non-italic text renders it correctly, then it looks like a rendering issue, that would need working around with extra padding in the TextView to allow space for the italic letters.

    0 讨论(0)
  • 2021-02-18 13:19

    I encountered the same problem but with EditText when used some fonts. My solution works also with TextView:

    1. Use padding

    2. As TextView using Canvas.clipRect(float, float, float, float) in onDraw method to crop - create custom Canvas class and override this method (leave it empty).

    3. Next сreate custom TextView and override two methods onSizeChanged and onDraw.

    In onSizeChanged create bitmap with the size of TextView and our custom Canvas.

    In onDraw first draw in bitmap by passing our custom Canvas to method super.onDraw. After that draw bitmap to target сanvas.

    More detailed in my answer to the similar question here

    0 讨论(0)
  • 2021-02-18 13:27

    This is my solution: Format textview and measure. After that set width of textview with 1 pixel add to the width measured.

        TextView textView = new TextView(this);
        textView.setText("Text blah blah");
        textView.setTypeface(typeface, Typeface.BOLD_ITALIC)
        textView.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
        textView.setLayoutParams(new LayoutParams(textView.getMeasuredWidth() + 1, LayoutParams.WRAP_CONTENT));
    

    Working for me. Hope these help.

    0 讨论(0)
  • 2021-02-18 13:27

    To narrow down the source of the error try setting android:letterSpacing="0" This was the reason for cut off letters in my case. Another hint for too much letter spacing is that the cut off part get bigger when the text has more letters in it.

    0 讨论(0)
  • 2021-02-18 13:32

    You could always create custom TextView that will use for example this font (cause in fact this is a problem with italic type):

    Typeface tf = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-LightItalic.ttf");
    setTypeface(tf);
    

    More details here.

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