get Font Height for Paint - Android android.graphics

Android examples for android.graphics:Font

Description

get Font Height for Paint

Demo Code

import android.graphics.Paint;
import android.graphics.Paint;
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.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern;

public class Main{

    public static int getFontHeight(float fontSize) {
        Paint m_paint = new Paint();
        m_paint.setTextSize(fontSize);//from ww w . j  a v  a 2s. com
        FontMetrics fm = m_paint.getFontMetrics();
        return (int) Math.ceil(fm.descent - fm.top) + 2;
    }

}

Related Tutorials