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 the activity 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-padding
Paint.setstyle (Style.fill);
Draw a rectangle
Canvas.drawrect (New Rect (0, 0, getwidth (), GetHeight ()), paint);
Draw a hollow rectangle
Set color
Paint.setcolor (color.red);
Set style-Hollow rectangle
Paint.setstyle (Style.stroke);
Draw a rectangle
Canvas.drawrect (New Rect (), paint);
Painting text
Set color
Paint.setcolor (Color.green);
Painting text
Canvas.drawtext ("Hello", m, paint);
Drawing
To generate a bitmap from a resource file
Bitmap Bitmap = Bitmapfactory.decoderesource (Getresources (), R.drawable.icon);
Drawing
Canvas.drawbitmap (bitmap, paint);
}
}
}