get Font height - Android Graphics

Android examples for Graphics:Font

Description

get Font height

Demo Code


//package com.java2s;

import android.graphics.Paint;

import android.widget.TextView;

public class Main {
    /**/*from  w  ww  .j a v  a2  s.c o m*/
     * get Font height
     *
     * @param view
     * @return
     */
    public static int getFontHeight(TextView view) {
        Paint paint = new Paint();
        paint.setTextSize(view.getTextSize());
        Paint.FontMetrics fm = paint.getFontMetrics();
        //descent:The recommended distance below the baseline for singled spaced text.
        //ascent:The recommended distance above the baseline for singled spaced text.
        return (int) (Math.ceil(fm.descent - fm.ascent));
    }
}

Related Tutorials