draw Paint Text Align Left - Android Graphics

Android examples for Graphics:Paint

Description

draw Paint Text Align Left

Demo Code


//package com.java2s;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;

public class Main {

    public static void drawTextAlignLeft(Context context, Canvas canvas,
            Paint textPaint, String text, int centerY, int left) {
        textPaint.setTextAlign(Paint.Align.LEFT);

        canvas.drawText(text, left, getDrawTextY(centerY, textPaint),
                textPaint);//  ww  w  .j  av a 2  s.  co m
    }

    public static int getDrawTextY(int textCenterY, Paint paint) {
        return (int) (textCenterY + 0.3 * getDrawTextHeight(paint));
    }

    public static int getDrawTextHeight(Paint paint) {
        Paint.FontMetrics fm = paint.getFontMetrics();
        return (int) Math.ceil(fm.descent - fm.ascent);
    }
}

Related Tutorials