Android在用画笔的时候有三种Style,分别是
Paint.Style.STROKE 只绘制图形轮廓(描边)
Paint.Style.FILL 只绘制图形内容
Paint.Style.FILL_AND_STROKE 既绘制轮廓也绘制内容
private static final String DRAW_TEXT = "一二三四";
private void drawText(Canvas canvas) {
Paint paint = new Paint();
paint.setColor(Color.RED);
paint.setDither(true);
paint.setStrokeWidth(3);
paint.setTextSize(100);
paint.setAntiAlias(true);
//测量文本高
Rect textBounds = new Rect();
paint.getTextBounds(DRAW_TEXT, 0, DRAW_TEXT.length(), textBounds);
int textH = textBounds.height();
paint.setStyle(Paint.Style.STROKE);
canvas.drawText(DRAW_TEXT, 0, 100 + textH * 0, paint);
paint.setStyle(Paint.Style.FILL);
canvas.drawText(DRAW_TEXT, 0, 100 + textH * 1 + 50, paint);
paint.setStyle(Paint.Style.FILL_AND_STROKE);
canvas.drawText(DRAW_TEXT, 0, 100 + textH * 2 + 100, paint);
}
看一下绘制文字的效果图:
STROKE和FILL_AND_STROKE的粗细是一样的,FILL最细
文章很短,快餐式
原文链接:https://blog.youkuaiyun.com/csm_qz/article/details/50936606