Android examples for Graphics:Paint
get Text Width via Paint
//package com.java2s; import android.graphics.Paint; import android.graphics.Rect; public class Main { public static Rect textBounds = null; public static int getTextWidth(String str, Paint paint) { int width = 0; if (str != null && str.length() != 0) { if (textBounds == null) { textBounds = new Rect(); }//from w w w. j a v a 2 s .c om paint.getTextBounds(str, 0, str.length(), textBounds); width = textBounds.width(); } return width; } }