Android String Width Get getStringsWidth(TextPaint paint, String text)

Here you can find the source of getStringsWidth(TextPaint paint, String text)

Description

get the width for a string with specified paint.

Parameter

Parameter Description
paint a parameter
text a parameter

Return

: int

Declaration

public static int getStringsWidth(TextPaint paint, String text) 

Method Source Code

//package com.java2s;
import android.graphics.Rect;
import android.text.TextPaint;

public class Main {
    /**//from   w  w  w. jav  a  2 s.  c  o m
     * get the width for a string with specified paint.
     * @Title: getStringsWidth 
     * @Description: TODO
     * @param paint
     * @param text
     * @return string width
     * @return: int
     */
    public static int getStringsWidth(TextPaint paint, String text) {
        Rect rect = new Rect();
        paint.getTextBounds(text, 0, text.length(), rect);
        return rect.width();
    }
}

Related

  1. displayWidth(String s)