Paint类常用方法
Paint类代表画笔,用来描述图形的颜色和风格,如线宽、颜色、透明度和填充效果等信息。使用Paint类时,首先要创建它的实例对象,然后通过该类提供的方法来更改Paint对象的默认设置。Paint类提供的常用方法如下:
| 方法 | 描述 |
| — | — |
| setAlpha(int a) | 设置透明度 |
| setARGB(int a, int r, int g, int b) | 绘制颜色 |
| setColor(int color) | 设置颜色 |
| setShader(Shader shader) | 设置渲染效果 |
| setShadowLayer(float radius, float dx, float dy, int color) | 设置阴影 |
| setStrokeWidth(float width) | 设置画笔粗细 |
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// 把整张画布绘制成白色
canvas.drawColor(Color.WHITE);
Paint paint = new Paint();
/**
-
设置画笔的锯齿效果,去锯齿
-
设置画笔颜色,蓝色
-
设置画笔风格,空心
-
设置空心画笔的宽度,3
*/
paint.setAntiAlias(true);
paint.setColor(Color.BLUE);