from:http://blog.csdn.net/xiadik/article/details/41648181
PackageCom.wangran.beautiful_girl_show.view;ImportCom.wangran.beautiful_girl_show.view.photoview.PhotoView;ImportAndroid.content.Context;ImportAndroid.graphics.Canvas;ImportAndroid.graphics.Color;ImportAndroid.graphics.Paint;ImportAndroid.graphics.RectF;ImportAndroid.graphics.Typeface;ImportAndroid.util.AttributeSet;/*** ImageView to show progress *@authorXiacao*/ Public classProgressimageviewextendsImageView {Private Static FinalString TAG = "Progressimageview"; PrivateContext Mcontext; Public Static Final intFont_size = 14; Public Static Final intRound_width = 50; Public Static Final intStroke_width = 7; Private intmfontsize; Private intMroundwidth; Private intMstrokewidth; PrivatePaint Mpaint; Private Booleanmshowprogress; Private intmprogress; Private floatmtexty; Private intMcenterx; Private intMcentery; Private intMradius; PrivateRECTF Moval; PublicProgressimageview (Context context) {Super(context); Mcontext=context; } PublicProgressimageview (Context context, AttributeSet attrs) {Super(context, attrs); Mcontext=context; } Private voidinit () {floatScale =mcontext.getresources (). Getdisplaymetrics (). density; Mfontsize= (int) (Font_size *Scale ); Mroundwidth= (int) (Round_width *Scale ); Mstrokewidth= (int) (Stroke_width *Scale ); Mpaint=NewPaint (); Mpaint.setantialias (true); Mpaint.settextsize (mfontsize); Mcenterx= GetWidth ()/2; Mcentery= GetHeight ()/2; Mradius= MROUNDWIDTH/2; Mtexty= Mcentery + mfontsize * 11.0F/28; Moval=NewRECTF (Mcenterx-mradius, Mcentery-Mradius, Mcenterx+ Mradius, Mcentery +Mradius); } Public voidOnDraw (canvas canvas) {if(mshowprogress) {if(Mcenterx = = 0 | | mcentery = = 0) {init (); } //draw the outermost big ringMpaint.setcolor (Color.dkgray); Mpaint.setstyle (Paint.Style.STROKE); Mpaint.setstrokewidth (Mstrokewidth); Canvas.drawcircle (Mcenterx, Mcentery, Mradius, Mpaint); //Draw Progress PercentageMpaint.setstrokewidth (0); Mpaint.setcolor (Color.White); Mpaint.settypeface (Typeface.monospace); Mpaint.settextalign (Paint.Align.CENTER); String Progressstr= mprogress + "%"; Canvas.drawtext (Progressstr, Mcenterx, Mtexty, Mpaint); //draw the progress of the ringmpaint.setstrokewidth (mstrokewidth); Mpaint.setcolor (Color.White); Canvas.drawarc (Moval,0, mprogress/100 *,false, Mpaint); } Else { Super. OnDraw (canvas); } } Public voidstartprogress () {mshowprogress=true; Setprogress (0); } Public voidSetprogress (intprogress) { if(mshowprogress) {mprogress=progress; Invalidate (); } } Public voidcloseprogress () {mshowprogress=false; }}
Android custom control's circular progress bar ImageView