get Font Height Metrics - Android android.graphics

Android examples for android.graphics:Font

Description

get Font Height Metrics

Demo Code

import android.graphics.Paint;
import android.graphics.Paint;
import android.util.FloatMath;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.regex.Pattern;

public class Main{

    public static int getFontHeight(float fontSize) {
        Paint m_paint = new Paint();
        m_paint.setTextSize(fontSize);//www. ja  va  2 s.co  m
        FontMetrics fm = m_paint.getFontMetrics();
        return (int) FloatMath.ceil(fm.descent - fm.top) + 2;
    }

}

Related Tutorials