Android 获取文字的宽度、高度

public float getFontWidth(Paint paint, String text) {
    return paint.measureText(text);

}

/**
 * @return 返回指定的文字高度
 */
public float getFontHeight(Paint paint) {
    FontMetrics fm = paint.getFontMetrics();
    //文字基准线的下部距离-文字基准线的上部距离 = 文字高度
    return fm.descent - fm.ascent;
}

你可能感兴趣的:(android)