The following is an introduction to Android through the OnDraw implementation of the drawing operation in the view of the sample code for detailed analysis, the need for friends can come to refer to the next
The Android drawing operation implements the drawing in the OnDraw function by inheriting the view implementation.
The following is a simple example:
Copy Code code as follows:
public class Androidtest extends activity {
/** called when the "activity is" is a. */
@Override
public void OnCreate (Bundle savedinstancestate) {
super.oncreate (savedinstancestate);
myview mv = new MyView (this);
Setcontentview (MV);
}
public class MyView extends View {
MyView (Context context) {
super (context);
}
@Override
protected void OnDraw (Canvas Canvas) {
//TODO auto-generated method stub
Super.ondraw (canvas);
//First define a paint
Paint Paint = new Paint ();
//Draw rectangular area-filled rectangle
//Set color
Paint.setcolor (Color.Blue);
//Set style-fill
Paint.setstyle (Style.fill);
//Draw a rectangle
Canvas.drawrect (New Rect (0, 0, getwidth (), GetHeight ()), paint);
//Painted hollow rectangle
//Set color
Paint.setcolor (color.red);
Set style-Hollow rectangle
Paint.setstyle (Style.stroke);
//Draw a rectangle
Canvas.drawrect (New Rect (a), paint);
//Painting text
//Set color
Paint.setcolor (Color.green);
//Painting text
canvas.drawtext ("Hello", m, paint);
//Drawing
//Generate bitmaps from the resource file
Bitmap Bitmap = Bitmapfactory.decoderesource (Getresources (), R.drawable.icon);
//Drawing
Canvas.drawbitmap (bitmap, n, paint);
}
}
}