Example usage for android.text TextPaint getFontMetrics

List of usage examples for android.text TextPaint getFontMetrics

Introduction

In this page you can find the example usage for android.text TextPaint getFontMetrics.

Prototype

public FontMetrics getFontMetrics() 

Source Link

Document

Allocates a new FontMetrics object, and then calls getFontMetrics(fm) with it, returning the object.

Usage

From source file:Main.java

public static float getDesiredHeight(TextPaint paint) {
    FontMetrics fm = paint.getFontMetrics();
    return (float) Math.ceil(fm.descent - fm.ascent);
}

From source file:Main.java

public static int getDanmuHeight(TextPaint textPaint) {
    Paint.FontMetrics fontMetrics = textPaint.getFontMetrics();
    return (int) (fontMetrics.bottom - fontMetrics.top + .5f);
}

From source file:Main.java

public static int getFontHeight(Context context, float fontSize) {
    TextPaint paint = new TextPaint();
    setTextSize(context, paint, fontSize);
    FontMetrics fm = paint.getFontMetrics();
    return (int) Math.ceil(fm.descent - fm.ascent);
}