//画笔Pain的简单使用
Paint paint = new Paint();
// 设置颜色
paint.setColor(color);
// 设置抗锯齿
paint.setAntiAlias(true);
// 防抖动
paint.setDither(true);
// 设置字体的大小
paint.setTextSize(textSize);
//设置画笔的样式,为FILL,FILL_OR_STROKE,或STROKE
paint.setStyle(Paint.Style style):
// 获取基线baseLine的y坐标
Paint.FontMetricsInt fontMetrics = paint.getFontMetricsInt();
int dy = (fontMetrics.bottom - fontMetrics.top) / 2 - fontMetrics.bottom;
int baseLine = getHeight() / 2 + dy;
//获取Paint绘制的文本宽度/高度
public int getTextWidth(String text,Paint paint) {
Rect bounds = new Rect();
paint.getTextBounds(text,text.length(),bounds);
int width = bounds.left + bounds.width();
return width;
}
public int getTextHeight(String text,Paint paint){
Rect bounds = new Rect();
paint.getTextBounds(text,text.length(),bounds);
int height = bounds.bottom + bounds.height();
return height;
}