get Text Height via Paint - Android Graphics

Android examples for Graphics:Paint

Description

get Text Height via Paint

Demo Code


//package com.java2s;
import android.graphics.Paint;
import android.graphics.Rect;

public class Main {
    public static Rect textBounds = null;

    public static int getTextHeight(String str, Paint paint) {
        int height = 0;
        if (str != null && str.length() != 0) {
            if (textBounds == null) {
                textBounds = new Rect();
            }/*w  ww . j  av a  2s . co m*/
            paint.getTextBounds(str, 0, str.length(), textBounds);
            height = textBounds.bottom - textBounds.top;
        }
        return height;
    }
}

Related Tutorials