Java tutorial
//package com.java2s; import android.graphics.Paint; import android.text.TextUtils; public class Main { public static float getTextWidth(Paint paint, String text, float textSize) { if (TextUtils.isEmpty(text)) { return 0; } paint.setTextSize(textSize); float[] widths = new float[text.length()]; paint.getTextWidths(text, widths); float totalWidth = 0; for (int i = 0; i < widths.length; i++) { totalWidth += widths[i]; } return totalWidth; } }