Example usage for android.graphics Paint setTextSize

List of usage examples for android.graphics Paint setTextSize

Introduction

In this page you can find the example usage for android.graphics Paint setTextSize.

Prototype

public void setTextSize(float textSize) 

Source Link

Document

Set the paint's text size.

Usage

From source file:Main.java

public static int getFontHeight(float fontSize) {
    Paint paint = new Paint();
    paint.setTextSize(fontSize);
    Paint.FontMetrics fm = paint.getFontMetrics();
    return (int) Math.ceil(fm.descent - fm.top) + 2;
}

From source file:Main.java

public static int getFontHeight(TextView textView) {
    Paint paint = new Paint();
    paint.setTextSize(textView.getTextSize());
    Paint.FontMetrics fm = paint.getFontMetrics();
    return (int) Math.ceil(fm.bottom - fm.top);
}

From source file:Main.java

public static Rect getTextRect(String text, float size) {
    Paint pFont = new Paint();
    pFont.setTextSize(size);
    Rect rect = new Rect();
    pFont.getTextBounds(text, 0, text.length(), rect);
    return rect;/*ww  w.ja  v  a 2 s. c om*/
}

From source file:Main.java

private static int getFontHeight(TextView tv) {
    Paint paint = new Paint();
    paint.setTextSize(tv.getTextSize());
    Paint.FontMetrics fm = paint.getFontMetrics();
    return (int) Math.ceil(fm.bottom - fm.top);
}

From source file:Main.java

public static int measureTextWidth(String text, int textsize) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(textsize);
    return (int) paint.measureText(text);
}

From source file:Main.java

public static int measureTextHeight(int textsize) {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(textsize);
    Paint.FontMetrics metrics = paint.getFontMetrics();
    return (int) Math.ceil(metrics.descent - metrics.ascent);
}

From source file:Main.java

public static Rect getTextBounds(float textSize, String text) {
    Rect bounds = new Rect();
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setTextSize(textSize);

    paint.getTextBounds(text, 0, text.length(), bounds);

    bounds.height();//w  w w.  j av a  2s  .co  m
    return bounds;
}

From source file:Main.java

public static Paint getScoreColor() {
    Paint paint = new Paint();
    paint.setColor(Color.WHITE);//from  ww  w  .  j a v a 2s  . c  o m
    paint.setTextSize(80);
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setShadowLayer(3, 5, 5, Color.BLACK);
    return paint;
}

From source file:Main.java

public static Paint getGameOverColor() {
    Paint paint = new Paint();
    paint.setColor(Color.WHITE);//ww  w.  jav  a2  s.c  om
    paint.setTextSize(80);
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    paint.setShadowLayer(2, 3, 3, Color.GRAY);
    return paint;
}

From source file:Main.java

public static Paint getGameOverRestartMessageColor() {
    Paint paint = new Paint();
    paint.setColor(Color.YELLOW);
    paint.setTextSize(20);
    paint.setTypeface(Typeface.DEFAULT_BOLD);
    //        paint.setShadowLayer(2, 3, 3, Color.WHITE);
    return paint;
}