get Paint Text Height - Android Graphics

Android examples for Graphics:Paint

Description

get Paint Text Height

Demo Code


//package com.java2s;

import android.graphics.Paint;

import android.graphics.Rect;

public class Main {
    public static int getTextHeight(String text, Paint paint) {
        Rect rect = getTextBounds(text, paint);
        return rect.height();
    }/*from w w w. j ava 2 s .com*/

    public static Rect getTextBounds(String text, Paint paint) {
        Rect rect = new Rect();
        paint.getTextBounds(text, 0, text.length(), rect);
        return rect;
    }
}

Related Tutorials