Android custom control's circular progress bar ImageView

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.