Code example for TextPaint

Methods: setAlphasetAntiAliassetTextSizesetTypefacegetDesiredWidth

0
    ++n;
    return (n <= 0) ? 1 : n;
  } 
 
  private void prepareLayout() { 
    float desiredWidth = Layout.getDesiredWidth(text, paint);
 
    textWidth = (int)Math.ceil(desiredWidth);
    if (textWidth > maxWidthPixels) {
      textWidth = maxWidthPixels;
    } 
    else if (textWidth <= 0) {
      textWidth = 1;
    } 
 
    Layout.Alignment _alignment = Layout.Alignment.ALIGN_NORMAL;
 
    if (alignment == 1) {
      _alignment = Layout.Alignment.ALIGN_CENTER;
    } 
    else if (alignment == 2) {
      _alignment = Layout.Alignment.ALIGN_OPPOSITE;
    } 
 
    layout = new StaticLayout(text, paint, textWidth,
        _alignment, 1, 0, false);
 
    textHeight = (int)Math.ceil(layout.getHeight());
    if (textHeight > maxHeightPixels) {
      textHeight = maxHeightPixels;
    } 
    else if (textHeight <= 0) {
      textHeight = 1;
    } 
  } 
 
  private void prepare() { 
    paint = new TextPaint();
 
    Typeface typeface = getTypeface();
    if (typeface != null) {
      paint.setTypeface(typeface);
    } 
    if (fontSize > 0) {
      paint.setTextSize(fontSize);
    } 
    paint.setAntiAlias(true);
    paint.setAlpha(255);
 
    prepareLayout(); 
 
    textureWidth = getNextPowerOfTwo(textWidth);
    textureHeight = getNextPowerOfTwo(textHeight);
Connect your IDE to all the code out there  Get Codota for Java