正在从一个特定的字体切断文本 [英] Text being cut off from front for a particular font

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

问题描述

新行上的每个单词的第一个字母被切断为 de 。

看到图片这是一个padding.If我不使用任何填充,它会像图片2

这是我的代码



$ p $ < 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驴象鸵鸟
/>

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

  protected void onDraw(Canvas canvas){
// TODO自动生成的方法存根
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);

code $


任何人都可以帮忙。





请求屏幕截图



是否有一种方法可以将一些额外的空间向左TextView的一面?

解决方案

最后我为此做了一个工作。这是一个字体问题,我不确定它可以被任何所以我所做的是,首先得到TextView布局,并得到每一行的结束和开始,因此获得每一行中的字符串。现在每行前添加空格。这里是整个代码。可以帮助某人

  ArrayList< String> lines = new ArrayList< String>(); 
ArrayList< String> newLines = new ArrayList< String>();
String line =;
String text = getText()。toString();
布局布局= 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(\\\\
+);
// float textsize = getTextSize();

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


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

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

This is my code

<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"
    />

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);
}

Can anyone help.?

Edit

Requested screenshot

Is There a way to put some extra space towards left side of the 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天全站免登陆