draw Text Multiline on Canvas - Android Graphics

Android examples for Graphics:Canvas

Description

draw Text Multiline on Canvas

Demo Code


//package com.java2s;
import java.util.StringTokenizer;

import android.graphics.Canvas;

import android.graphics.Paint;

public class Main {

    public static void drawTextMultiline(Canvas canvas, String str,
            float x, float y, Paint paint) {
        float lineHeight = (-paint.ascent() + paint.descent()) * 1.1f;
        float top = y + -paint.ascent();

        // ?? ??? ???????.
        StringTokenizer tok = new StringTokenizer(str, "\n");
        while (tok.hasMoreTokens()) {
            canvas.drawText(tok.nextToken(), x, top, paint);
            top += lineHeight;/*from w  w w  .j  a  v  a  2 s  . c o m*/
        }
    }
}

Related Tutorials