Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.Paint; import android.graphics.Rect; import android.text.TextUtils; public class Main { public static Rect getTextRect(String text, Paint paint) { Rect rect = new Rect(); if (!TextUtils.isEmpty(text)) { paint.getTextBounds(text, 0, text.length(), rect); } return rect; } }