Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
816 views
in Technique[技术] by (71.8m points)

android - Text being cut off from front for a particular font

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

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

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

enter image description here

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...