In Android game development, use the classes in android.graphics to draw 2D vector graphs and text.
Canvas Canvases
The drawing in Android should inherit the view component and rewrite its ondraw (canvas canvas) method.
Canvas represents the canvas on the specified view, common methods
Two paint brushes Paint
Paint represents a brush on canvas and is used primarily for drawing styles, including brush color, brush stroke thickness, fill style, and so on.
In general, it can be divided into two categories, one is related to drawing, the other is related to text drawing.
Common methods
Three Paths Path
Path represents the path drawn on the canvas, which can be any number of straight lines connected to any shape.
Four examples
protected void OnDraw (canvas canvas) {super.ondraw (canvas); Draw the whole canvas into white canvas.drawcolor (color.white); Create a paint brush paint paint = new paint (); Set the brush properties Paint.setantialias (TRUE);//anti-aliasing Paint.setcolor (color.red);//Set paint brush color to red Paint.setstyle (Paint.Style.STROK E);//Set the brush style to hollow paint.setstrokewidth (3);//Set the outer frame width of the paint//Draw a hollow round canvas.drawcircle (. Draw a hollow square canvas.drawrect (ten, N, a, a, and paint); Draw a hollow rectangular canvas.drawrect (ten, 70,200, paint); Draw a hollow oval RECTF re=new RECTF (10,220,70,250); Canvas.drawoval (Re, paint); Draw a hollow triangle path path=new path ();p Ath.moveto ();p Ath.lineto (70,330);p Ath.lineto (40,270);p ath.close (); Canvas.drawpath (path, paint);//Draw a hollow trapezoid path path1=new path ();p Ath1.moveto (410);p Ath1.lineto (70,410); Path1.lineto (55,350);p Ath1.lineto (+);p ath1.close (); Canvas.drawpath (path1, paint); Modify Brush Properties Paint.setstyle (Paint.Style.FILL);//Set brush style to solid paint.setcolor (color.blue);//Set the brush color//Draw a solid round canvas.drawcircle (120,40,30, paint);//Draw a solid square canvas.drawrect (full, full, full, and paint);// Draw a solid rectangle canvas.drawrect (n, 150,200, paint);//Draw a solid ellipse RECTF re2=new RECTF (90,220,150,250); Canvas.drawoval (Re2, paint);//Draw a solid triangle path path2=new path ();p Ath2.moveto (All-in-one);p Ath2.lineto (150,330);p Ath2.lineto (120,270); Path2.close (); Canvas.drawpath (path2, paint);//Draw a solid trapezoid path path3=new path ();p Ath3.moveto (410);p Ath3.lineto ( 150,410);p Ath3.lineto (135,350);p Ath3.lineto;p ath3.close (); Canvas.drawpath (path3, paint);//Set gradient shader Mshader=new lineargradient (0,0,100,100, New Int[]{color.red,color.green,color.blue,color.yellow}, Null,Shader.Ti Lemode.repeat);p Aint.setshader (Mshader);//Draw a gradient-colored circle canvas.drawcircle (200,40,30, paint);//Draw a gradient-colored square canvas.drawrect (Canvas.drawrect, N, V, max, paint);//Draw a gradient-colored rectangle (230,200, paint);//Draw a gradient-colored ellipse rectf re3=new RECTF (170,220,2 30,250); Canvas.drawoval (Re3, paint);//Draw a gradient color triangle path path4=new path ();p Ath4.moveto (170,330);Path4.lineto (230,330);p Ath4.lineto (200,270);p ath4.close (); Canvas.drawpath (Path4, paint);//Draw a gradient-colored trapezoid path path5=new Path ();p Ath5.moveto (410);p Ath5.lineto (230,410);p Ath5.lineto (215,350);p Ath5.lineto (185);p ath5.close (); Canvas.drawpath (Path5, paint);//Draw Text paint.settextsize (24);//Set the font size Canvas.drawtext (getresources (). GetString ( R.STRING.STR_TEXT1), Canvas.drawtext (Getresources (). getString (R.STRING.STR_TEXT2), +------ Canvas.drawtext (Getresources (). getString (R.STRING.STR_TEXT3), (), Canvas.drawtext (getresources). GetString (R.STRING.STR_TEXT4), Canvas.drawtext (Getresources (). getString (R.STRING.STR_TEXT5), 240, Canvas.drawtext (Getresources () getString (R.STRING.STR_TEXT6), 390, paint); }
Four
Reference article:
Http://www.cnblogs.com/stulife/archive/2010/08/19/1803313.html
Http://www.cnblogs.com/-oyk/archive/2011/10/25/2223624.html
http://blog.csdn.net/u010142437/article/details/9200465
Graphic drawing in Android game development: use of canvas and paint