Android examples for android.graphics:Paint
Create Paint from text and font size
import android.graphics.Paint; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main{ public static int GetPixelByText(float textSize, String text) { Paint mTextPaint = new Paint(); mTextPaint.setTextSize(textSize); mTextPaint.setFakeBoldText(true); mTextPaint.setAntiAlias(true); //from ww w. jav a 2 s . c o m return (int) (mTextPaint.measureText(text) + textSize); } }