Java tutorial
//package com.java2s; import android.graphics.Paint; import android.graphics.Rect; public class Main { public static float measureTextWidth(Paint paint, String str) { if (paint == null || str == null) { return 0; } return paint.measureText(str); } public static Rect measureText(Paint paint, String str) { Rect rect = new Rect(); paint.getTextBounds(str, 0, str.length(), rect); return rect; } }