calculate Y When Text Align Center - Android android.graphics

Android examples for android.graphics:Canvas

Description

calculate Y When Text Align Center

Demo Code

import android.graphics.Paint;

public class Main {

  public static float calcYWhenTextAlignCenter(int aCanvasHeight, Paint aPaint) {
    if (aPaint == null) {
      return 0;/*w  ww .j ava  2  s .c o m*/
    }

    final float fontHeight = aPaint.getFontMetrics().bottom - aPaint.getFontMetrics().top;
    return ((aCanvasHeight - fontHeight) / 2 - aPaint.getFontMetrics().top);
  }

}

Related Tutorials