针对特定字体从前面截断文本 [英] Text being cut off from front for a particular font

查看:16
本文介绍了针对特定字体从前面截断文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 us denealian cursive font,换行中每个单词的第一个字母被截断.

The first letter of each word on new line is cut off for us denealian cursive font.

看这张带有填充的图片.如果我没有使用任何填充,它将像图片 2

see the picture this one is with padding.If I am not using any padding ,it will be like in pic 2

这是我的代码

<com.font.anything.writinghelper
    android:id="@+id/textView" 
   android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:textColor="#000000"
    android:padding="20dip"
    android:textSize="60sp"
    android:text="japanese google donkey elephant ostrich"
    />

这里的写作助手是一个扩展 textview 的类,只是为了给文本加下划线

Here writing helper is a class extending textview just to underline the text

     protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    Rect r = mRect;
    int padding =55;
    Paint paint = mPaint;
    int count = getLineCount();
    for (int i = 0; i < count; i++) {
    int baseline = getLineBounds(i, r);
    canvas.drawLine(r.left - padding, baseline, r.right + padding,
            baseline, paint);
    }
    super.onDraw(canvas);
}

有人可以帮忙吗?

编辑

请求的屏幕截图

有没有办法在 TextView 的左侧放置一些额外的空间?

Is There a way to put some extra space towards left side of the TextView ?

推荐答案

最后我解决了这个问题..这是一个字体问题,我不确定它是否可以通过任何其他方式修复.所以我做了什么是,首先获取 TextView 布局并获取每行的结尾和开头,从而在每行中获取字符串.现在在每行前面附加空格.这是整个代码.可能会帮助其他人.

Finally I made a work around for this..It's a font issue and I am not sure it can be fixed by any other way.So what I have done is ,first get the TextView Layout and get the end and start of each line and hence obtain string in each line.Now append space in front of each line .Here is the entire code.May help someone else.

    ArrayList<String> lines = new ArrayList<String>();
    ArrayList<String> newLines = new ArrayList<String>();
    String line="";
    String text = getText().toString();
    Layout layout = getLayout();
    int start=0;
    int end;

    for (int i=0; i<count; i++) {
        end = layout.getLineEnd(i);

        lines.add(text.substring(start,end));
        line = lines.get(i);
        start = end;
        String nwText = "";
        nwText = " "+ line+" ";
        newLines.add(nwText);
    }
    Paint mPaint = getPaint();
    int i = 0;
   // String[] textLines = Results.split("\n+");
    //float textsize = getTextSize();

    for (String textLine : newLines)
    {
       // mPaint.setTextSize(textsize);
        int baseline = getLineBounds(i, r);
        canvas.drawText(textLine, 0, baseline, mPaint);
       i++;
    }

这篇关于针对特定字体从前面截断文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆