get string Pixel Width - Android android.graphics

Android examples for android.graphics:Paint

Description

get string Pixel Width

Demo Code

import android.graphics.Paint;
import android.graphics.Rect;

public class Main {

  public static int getPixWidth(String str, Paint paint) {
    Rect rect = new Rect();

    paint.getTextBounds(str, 0, str.length(), rect);

    return rect.width();
  }//ww  w. j  a va 2 s  .co m

}

Related Tutorials