Calculate the font height of a specific TextPaint - Android Graphics

Android examples for Graphics:Paint

Description

Calculate the font height of a specific TextPaint

Demo Code


//package com.java2s;

import android.graphics.Paint.FontMetrics;
import android.text.TextPaint;

public class Main {
    /**//from   w w w. j a v a  2 s  . c o m
     * Calculate the font height of a specific TextPaint
     * @param textPaint
     * @return
     */
    public static float calculateFontHeight(TextPaint textPaint) {
        FontMetrics fontMetrics = textPaint.getFontMetrics();
        return fontMetrics.bottom - fontMetrics.top;
    }
}

Related Tutorials