android学习日记08--Paint画笔

Paint

  要绘图,首先得调整画笔,待画笔调整好之后,再将图像绘制到画布Canvas上,
这样才可以显示在手机屏幕上。Android 中的画笔是 Paint类,Paint 中包含了很多方法对其属性进行设置,

Paint方法一般可分两类,图形的绘制和文本的绘制
主要方法如下:(没有全部列出,大家可以查看官方文档http://android.toolib.net/reference/android/graphics/Paint.html )

 1                 canvas.drawColor(Color.GREEN);
 2                 
 3                 Paint paint1 = new Paint();
 4                 canvas.drawCircle(40, 30, 20, paint1);
 5                 
 6                 //设置画笔无锯齿,默认有锯齿
 7                 paint1.setAntiAlias(true);
 8                 canvas.drawCircle(100, 30, 20, paint1);
 9                 
10                 //设置画笔的透明度
11                 canvas.drawText("无透明度", 100, 70, new Paint());
12                 Paint paint2 = new Paint();
13                 paint2.setAlpha(0x77);
14                 canvas.drawText("半透明度", 20, 70, paint2);
15                 
16                 //设置绘制文本的锚点
17                 canvas.drawText("锚点", 20, 90, new Paint());
18                 Paint paint3 = new Paint();
19                 
20                 //设置以文本的中心点绘制
21                 paint3.setTextAlign(Paint.Align.CENTER);
22                 canvas.drawText("锚点", 20, 105, paint3);
23                 
24                 //获取文本的长度
25                 Paint paint4 = new Paint();
26                 float len =paint4.measureText("文本宽度:");
27                 canvas.drawText("文本长度:"+len, 20, 130, new Paint());
28                 
29                 //设置画笔样式
30                 canvas.drawRect(new Rect(20,140,40,160), new Paint());
31                 Paint paint5 = new Paint();
32                 
33                 //设置画笔不填充
34                 paint5.setStyle(Style.STROKE);
35                 canvas.drawRect(new Rect(60,140,80,160), paint5);
36                 
37                 //设置画笔颜色
38                 Paint paint6 = new Paint();
39                 paint6.setColor(Color.GRAY);
40                 canvas.drawText("灰色", 30, 180, paint6);
41                 
42                 //设置画笔的粗细程度
43                 canvas.drawLine(20, 200,70, 200, new Paint());
44                 Paint paint7 = new Paint();
45                 paint7.setStrokeWidth(7);
46                 canvas.drawLine(20, 220,70, 220,paint7);
47                 
48                 //设置画笔绘制文本的字体粗细
49                 Paint paint8 = new Paint();
50                 paint8.setTextSize(20);
51                 canvas.drawText("文字尺寸", 20, 260, paint8);
52                 
53                 //设置画笔的ARGB分量 ,a值 (透明度)
54                 Paint paint9 = new Paint();
55                 paint9.setARGB(0x77, 0xff, 0x00, 0x00);
56                 canvas.drawText("红色半透明", 20, 290, paint9);

posted @ 2014-02-18 20:03  aiguozhe1991  阅读(528)  评论(0编辑  收藏  举报