in the general drawing of the user often only need to overwrite the OnDraw () method, but if you want to really complete the operation of the drawing, but also need to master the four core operating classes: android.graphics.Bitmap: Mainly represents a picture of the storage space, the included images can be from the file or created by the program; android.graphics.Paint: The main drawing Tool class, you can specify the style of the drawing; Android.graphics.Canvas: A platform formanipulating drawings and Bitmap , rather than providing the functionality of an artboard, OnDraw () This type is also defined in the parameters of the parameters that can be relied upon to accomplish specific drawing operations; android.graphics.drawable.Drawable: Draw a common parent class of graphics, you can paint a variety of graphics, layers and so on.
Custom MyView Components
<span style= "FONT-SIZE:18PX;" ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " tools:context= ". Mainactivity "> <com.example.paintpic.myview android:id=" @+id/myview " android:layout_width=" Wrap_content " android:layout_height=" Wrap_content "></com.example.paintpic.myview></ Linearlayout></span>
Main interface
<span style= "FONT-SIZE:18PX;" >package com.example.paintpic;import android.os.bundle;import Android.app.activity;import android.view.Menu; public class Mainactivity extends Activity { @Override protected void onCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); } } </span>
MyView Settings
<span style= "FONT-SIZE:18PX;" >package Com.example.paintpic;import Android.content.context;import Android.graphics.canvas;import Android.graphics.color;import Android.graphics.paint;import Android.graphics.rectf;import Android.util.attributeset;import Android.view.view;public class MyView extends View {public MyView (context context, AttributeSet attrs) {Super (context, attrs);//TODO auto-generated constructor stub} @Overrideprotected void OnDraw ( Canvas canvas) {//TODO auto-generated method stub//Canvas is an artboard object with a white background of canvas.drawcolor (color.white);//Paint Brush tool Paint Paint = new paint ();//Set brush color to Blue paint.setcolor (color.blue);//Draw circle on Artboard, Circle Center (50,50) Radius 50canvas.drawcircle (.) ;//Set the color of the brush to Red Paint.setcolor (color.red);//Draw Rectangle Canvas.drawrect (0, up, up, paint);//Brush color is green paint.setcolor ( Color.green);//Draw a straight line Canvas.drawline (120, A, a, a, and paint);p Aint.setcolor (Color.yellow);//rect rect=new rect //Canvas.drawrect (rect, paint);//use RECTF to draw polygons RECTF oval = new RECTF (); Oval.set (10.0f, 140.0f, 110.0f, 200.0f), Canvas.drawoval (oval, paint), oval = new RECTF (), Oval.set (150.0f, 140.0f , 210.0f, 200.0f); Canvas.drawarc (oval, 150.0f, 140.0f, true, paint);}} </span>
use canvas and point components to draw a variety of graphics, more for the development of the game, interested friends can understand the next
Next forecast: Bitmap graphics Components
Learn android<android basic drawing from scratch. 46 .>