First custom a circle, believe that the previous study everyone will draw a circle, write some custom properties under the values
Package Com.exaple.day01rikao;
Import Android.content.Context;
Import Android.content.res.TypedArray;
Import Android.graphics.Canvas;
Import Android.graphics.Color;
Import Android.graphics.Paint;
Import Android.util.AttributeSet;
Import android.view.MotionEvent;
Import Android.view.View;
public class Myview extends View {
int radius;
int color;
Private final static String Nam = "Chen";
Public Myview (context context, AttributeSet Attrs) {
Super (context, attrs);
/*
* TypedArray ta = context.obtainstyledattributes (attrs,
* R.styleable.myview); Radius = Ta.getint (R.styleable.myview_radius,
* 0); color = ta.getint (r.styleable.myview_mycolor, 0);
One of the more difficult ways
*/
Radius = Attrs.getattributeintvalue (Nam, "radius", 0);
color = Attrs.getattributeintvalue (Nam, "mycolor", 0);
Simple one-way
}
@Override
protected void OnDraw (canvas canvas) {
Paint PA = new paint ();
Paint PA1 = new paint ();
Float WI = canvas.getwidth ();
Float he = canvas.getheight ();
Pa.setcolor (color);
Pa1.setcolor (Color.White);
Canvas.drawcolor (Color.White);
Canvas.drawcircle (WI/2, HE/2, radius, PA);
/* Canvas.drawcircle (WI/2, HE/2, PA1); */
/* Canvas.drawtext ("hhhhhhhhhhhhhh", Wi/4, HE/4, PA); */
Super.ondraw (canvas);
}
/*
* @Override public boolean ontouchevent (Motionevent event) {WI =
* EVENT.GETX (); he = Event.gety (); This.invalidate ();
*
* return true; }
*/
}
Custom Properties View