android - Canvas animation slows down -


i creating custom view arc of 45% rotates around circular image. have achieved this, animation slows down animation proceeds , after sometime stops, can 1 me out problem same,

here's code

public class glowcircle extends imageview {      private context context;     private paint paintbitmap,paintring;     private bitmap imagebitmap;     private path path;     private int width,height;     private float radius;     private rectf oval,dst;     private string tag="glowcircle";     private int i=0;     private float strokewith;     private float strokemultiplier=1/10f;  // constructors      public glowcircle(context context) {         super(context);         initview(context);      }      public glowcircle(context context, attributeset attrs) {         super(context, attrs);         initview(context);      }      public glowcircle(context context, attributeset attrs, int defstyle) {         super(context, attrs, defstyle);         initview(context);     }    // overriden methods          @override     public void setimageresource(int resid) {         super.setimageresource(resid);         initview(context);     }      @override     public void setimagebitmap(bitmap bm) {         super.setimagebitmap(bm);         initview(context);     }      @override     public void setimageuri(uri uri) {         super.setimageuri(uri);         initview(context);     }      @override     protected void onlayout(boolean changed, int left, int top, int right,             int bottom) {         super.onlayout(changed, left, top, right, bottom);         width=getmeasuredwidth();         height=getmeasuredheight();           if (width<height){ //radius smallest measurement 1px padding             strokewith=strokemultiplier*width;             radius=(width/2f)-strokewith;          }else{             strokewith=strokemultiplier*height;             radius=(height/2f)-strokewith;         }         paintring.setstrokewidth(strokewith);      log.v(tag, "width: "+width+"str: "+strokewith+"ra: "+radius);        }      @override     protected void ondraw(canvas canvas) {         if (imagebitmap==null){             log.v(tag, "bitmap null");             return;         }         dst.set(strokewith, strokewith, width-strokewith, height-strokewith);         oval.set(strokewith/2, strokewith/2, width-strokewith/2, height-strokewith/2);         canvas.save();         path.addcircle(width/2,  height/2, radius, direction.ccw);         canvas.clippath(path);         canvas.drawbitmap(imagebitmap, null ,dst, paintbitmap);         canvas.restore();         if (i>360){             i=0;         }         canvas.drawarc(oval, i++, 45,false, paintring);         invalidate();      }   // class functions       private void initview(context context){          this.context=context;         paintbitmap=new paint();         paintring=new paint();         paintring.setstyle(style.stroke);         paintbitmap.setantialias(true);         paintring.setantialias(true);         paintbitmap.setfilterbitmap(true);         paintbitmap.setdither(true);// may slow try remove may crash on lower devices         paintring.setcolor(color.red);         bitmapdrawable bitmapdrawable=(bitmapdrawable) getdrawable(); // enables image;         imagebitmap=bitmapdrawable.getbitmap();          path=new path();         dst=new rectf();         oval=new rectf();     }  } 

got fix using external thread

look @ answer android canvas update issues


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -