1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
canvas.drawCircle(30,30,30,getPaintStoke(Color.RED));
canvas.drawCircle(100,30,30,getPaintFill(Color.BLACK));
// canvas.drawPoint(30,90,getPaintStoke(Color.RED));
canvas.drawLine(50,90,180,100,getPaintFill(Color.BLUE));
float[] pts={
50,100,180,110,
180,110,200,120,
200,120,180,130
};
canvas.drawLines(pts,getPaintFill(Color.GRAY));
canvas.drawRect(30,140,300,200,getPaintStoke(Color.GREEN));
canvas.drawRoundRect(30,210,300,280,45,45,getPaintFill(Color.RED));
canvas.drawRoundRect(330,210,600,280,45,45,getPaintStoke(Color.BLUE));
canvas.drawArc(30,300,300,370,80,80,false,getPaintStoke(Color.RED));
canvas.drawArc(330,300,600,370,80,80,false,getPaintFill(Color.RED));
canvas.drawArc(30,380,300,460,80,80,true,getPaintStoke(Color.RED));
canvas.drawArc(330,380,600,460,80,80,true,getPaintFill(Color.RED));
canvas.drawOval(30,480,300,540,getPaintStoke(Color.GREEN));
canvas.drawOval(330,480,600,540,getPaintFill(Color.GREEN));
canvas.drawText("测试文本",30,560,getPaintFill(Color.BLACK));
canvas.drawPosText("htc",new float[]{30,580,50,600,80,620},getPaintFill(Color.BLACK));
Path path = new Path();
path.moveTo(50,50);
path.lineTo(100,100);
path.lineTo(100,300);
path.lineTo(300,50);
canvas.drawPath(path,getPaintStoke(Color.BLACK));
//先创建两个大小一样的路径
//第一个逆向生成
Path CCWRectpath = new Path();
RectF rect1 = new RectF(50, 640, 240, 750);
CCWRectpath.addRect(rect1, Path.Direction.CCW);
//第二个顺向生成
Path CWRectpath = new Path();
RectF rect2 = new RectF(290, 640, 480, 750);
CWRectpath.addRect(rect2, Path.Direction.CW);
Paint paint = getPaintFill(Color.BLACK);
//先画出这两个路径
canvas.drawPath(CCWRectpath, paint);
canvas.drawPath(CWRectpath, paint);
//依据路径写出文字
String text="风萧萧兮易水寒,壮士一去兮不复返";
paint.setColor(Color.GRAY);
paint.setTextSize(35);
canvas.drawTextOnPath(text, CCWRectpath, 0, 18, paint);//逆时针生成
canvas.drawTextOnPath(text, CWRectpath, 0, 18, paint);//顺时针生成

代码实际效果