public class Yanghangcreditcircle extends View {private static final String TAG = "Yanghangcreditcircle"; private int resid = r.drawable.credit_report_turntable; Public Yanghangcreditcircle (Context context) {super (context); Init (); } public Yanghangcreditcircle (context context, AttributeSet Attrs) {Super (context, attrs); TypedArray t = GetContext (). Obtainstyledattributes (attrs,r.styleable.yanghangcreditcircle); Resid = T.getresourceid (r.styleable.yanghangcreditcircle_itembackground,r.drawable.credit_report_turntable); Init (); } private void Init () {progresspen = new Paint (); Progresspen.setantialias (TRUE); Progresspen.setstyle (Paint.Style.STROKE); Progresspen.setcolor (Color.White); Progresspen.setstrokewidth (margin);//The width margin of the brush box, the brush from the middle circlebmp = Bitmapfactory.decoderesource (Getresources (), RESID); Bmppaint.setantialias (TRUE); }//private float outsidepensize; Private Paint Progresspen; Private Bitmap circlebmp; private float degress = 0; float margin = UIUtil.INSTANCE.DipToPixels (10); Private Paint Bmppaint = new paint (); @Override protected void onmeasure (int widthmeasurespec, int heightmeasurespec) {Float width = Circlebmp.getwid Th () + (margin) * 2; float height = circlebmp.getheight () + (margin) * *; Widthmeasurespec = Measurespec.makemeasurespec ((int) width, measurespec.exactly); Heightmeasurespec = Measurespec.makemeasurespec ((int) height, measurespec.exactly); Setmeasureddimension (Widthmeasurespec, Heightmeasurespec); } public void setprogress (float degress) {this.degress = 5f + 205f*degress; Postinvalidate ();//Refresh OnDraw} public void setdegressprogress (float degress) {this.degress = degress; Postinvalidate (); }//(0,700] e//(700,840] d//(840,890] c//(890,930] b//(930,1000] A @OverrIDE public void OnDraw (canvas canvas) {super.ondraw (canvas); Rect rect = new rect (); Getdrawingrect (rect); int bmpwidth = (int) (Circlebmp.getwidth ()/2.0f); int bmpheight = (int) (Circlebmp.getheight ()/2.0f); Rect dstrect = new rect (); Dstrect.set (Rect.centerx ()-Bmpwidth, Rect.centery ()-Bmpheight, Rect.centerx () + Bmpwidth, Rect.centery ( ) + bmpheight), target area on//canvas rectf outsidecirclerect = new RECTF (Dstrect.left + MARGIN/2, Dstrect.top + MARGIN/2, Dstrect.left + dstrect.width ()-MARGIN/2, Dstrect.top + dstrect.width ()-MARGIN/2); Canvas.drawbitmap (circlebmp, NULL, dstrect, bmppaint);//Displays the entire picture in a specific rectangular area progresspen.setalpha (100); Canvas.drawarc (Outsidecirclerect, 160f, degress, False, Progresspen); float tmpdegress = degress; Canvas.save (); }}
Customization of Android View