Recent projects, there is a demand, is the fillet progress bar. As follows.
When the project time is very tight, not much to think how to achieve the best, directly to the art of the fillet progress bar cut into four parts. To do Canvas cut drawing. This can also achieve the effect, but the use of poor. Recent online search for a long time, found paint brush, masking layer function. Android.graphics.Paint.setXfermode (Xfermode xfermode) . One of the parameters is
mode.dst_out A basemap image that shows a non-intersection of the basemap and the upper layers. So there is a way of thinking, first draw the rounded rectangle progress bar, and then set the brush occlusion properties, and then draw the sector, to mask the rounded rectangle. This enables the function of the rounded rectangle progress bar.
Import Android.content.context;import Android.graphics.bitmap;import Android.graphics.bitmapfactory;import Android.graphics.canvas;import Android.graphics.color;import Android.graphics.paint;import Android.graphics.porterduff.mode;import Android.graphics.porterduffxfermode;import Android.graphics.RectF;import Android.util.attributeset;import Android.view.surfaceholder;import Android.view.surfaceview;public Class Mysurfaceview extends Surfaceview implements Surfaceholder.callback{surfaceholder Msurfaceholder;boolean isRun;/** Progress bar background **/bitmap bmpdes; /** move angle **/float m = 0;/** Circle radius that surrounds the background of the progress bar **/float r;/** move speed **/float speed;public mysurfaceview (context context, Attributese T attrs) {Super (context, attrs);//TODO auto-generated Constructor Stubmsurfaceholder = This.getholder (); Msurfaceholder.addcallback (this);/** load progress bar **/bmpdes = Bitmapfactory.decoderesource (Getresources (), R.DRAWABLE.D1). Copy (Bitmap.Config.ARGB_8888, true);/** compute radius **/r = (float) math.sqrt (Math.pow (Bmpdes.getwidth ()/2, 2) + MaTh.pow (Bmpdes.getheight ()/2, 2))/** calculated movement Speed **/speed = (float) (360/(25000/33.0)) according to 25s;} @Overridepublic void surfacechanged (Surfaceholder arg0, int arg1, int arg2, int arg3) {//TODO auto-generated method stub} @Overridepublic void surfacecreated (Surfaceholder arg0) {//TODO auto-generated method Stubisrun = True;new Thread () {Publ IC void Run () {while (Isrun) {Long start = System.currenttimemillis (); Canvas canvas = null;synchronized (msurfaceholder) {canvas = Msurfaceholder.lockcanvas (); if (canvas! = null) {Ongamedraw ( Canvas); if (canvas! = NULL && Msurfaceholder! = null) {msurfaceholder.unlockcanvasandpost (canvas);} M + = speed;if (M >=) m = 0;}} Long end = System.currenttimemillis ()-Start;if (end <) {try {thread.sleep (end);} catch (Interruptedexception e) {// TODO auto-generated catch Blocke.printstacktrace ();}}}}. Start ();} @Overridepublic void surfacedestroyed (Surfaceholder arg0) {//TODO auto-generated method Stubisrun = false;} private void Ongamedraw (canvas canvas) {/*CANvas.drawcolor (color.black); c = new Canvas (bmpdes); Paint paint = new paint ();p Aint.setantialias (True);p Aint.setxfermode (New Porterduffxfermode (mode.dst_out)), int sc = C.savelayer (0, 0, bmpdes.getwidth (), bmpdes.getheight (), NULL, layer_flags); C.drawarc (New RECTF (-(R-bmpdes.getwidth ( )/2),-(R-bmpdes.getheight ()/2), r*2, r*2), 0, M, true, paint); C.restoretocount (SC); Canvas.drawbitmap (bmpdes, 0, 0, NULL ); */Canvas.drawcolor (color.black); Paint paint = new paint (); Paint.setfilterbitmap (FALSE); Draw the second layer int sc = canvas.savelayer (0, 0, 0 + bmpdes.getwidth (), 0 + bmpdes.getheight (), NULL, canvas. Matrix_save_flag | Canvas.clip_save_flag | Canvas.has_alpha_layer_save_flag | Canvas.full_color_layer_save_flag | Canvas.clip_to_layer_save_flag); Draw a progress bar background canvas.drawbitmap (bmpdes, 0, 0, paint); Set the Occlusion property Paint.setxfermode (new Porterduffxfermode (Mode.dst_ouT)); Draw Occlusion Fan Canvas.drawarc (New RECTF (-(R-bmpdes.getwidth ()/2),-(R-bmpdes.getheight ()/2), r*2, r*2), 0, M, True, Pai NT); Feedback the second layer to the canvas Canvas.restoretocount (SC);}}
Source
http://download.csdn.net/detail/li_xiao_kang/8750631 Click to open link
Android Rounded Rectangle progress bar