get TextView Font height - Android User Interface

Android examples for User Interface:TextView Font

Description

get TextView Font height

Demo Code


//package com.java2s;

import android.graphics.Paint;
import android.graphics.Paint.FontMetrics;

import android.widget.TextView;

public class Main {
    /**/*from w  ww  .java2s.c om*/
     * get Font height
     *
     * @param view
     * @return
     */
    public static int getFontHeight(TextView view) {
        Paint paint = new Paint();
        paint.setTextSize(view.getTextSize());
        FontMetrics fm = paint.getFontMetrics();
        return (int) (Math.ceil(fm.descent - fm.ascent));
    }
}

Related Tutorials