calculate Y When Text Align Center on Canvas - Android Graphics

Android examples for Graphics:Canvas

Description

calculate Y When Text Align Center on Canvas

Demo Code


//package com.java2s;

import android.graphics.Paint;

public class Main {

    public static float calcYWhenTextAlignCenter(int aCanvasHeight,
            Paint aPaint) {//w  w  w.  j av a  2  s .  c  o m
        if (aPaint == null) {
            return 0;
        }

        final float fontHeight = aPaint.getFontMetrics().bottom
                - aPaint.getFontMetrics().top;
        return ((aCanvasHeight - fontHeight) / 2 - aPaint.getFontMetrics().top);
    }
}

Related Tutorials