Rotate compass in smooth way issue android -


this code use sensor class , other activity but
want compass rotate in smooth way use bitmap image on canvas bitmap not rotate in smooth way

  public class compassview extends view   {   private int mwidth;   private int mheight;   private float position = 0;   private  bitmap mycompasspointer;   public compassview(context context)    {   super(context);   mycompasspointer=bitmapfactory.decoderesource(getresources(),   r.drawable.pin_finder);   }   @override   protected void ondraw(canvas canvas)    {   int cx = (mwidth - mycompasspointer.getwidth()) >> 1;    int cy = (mheight - mycompasspointer.getheight()) >> 1;   if (position > 0)    {   canvas.rotate(position, mwidth >> 1, mheight >> 1);   }   //it set bitmap cx,cy position   canvas.drawbitmap(mycompasspointer, cx, cy, null);   canvas.restore();   }   public void updatedata(float position)   {   this.position = position;   invalidate();   }   protected void onmeasure(int widthmeasurespec, int     heightmeasurespec)    {   // todo auto-generated method stub   super.onmeasure(widthmeasurespec, heightmeasurespec);   mwidth = view.measurespec.getsize(widthmeasurespec);   mheight = view.measurespec.getsize(heightmeasurespec);   }   } 

you should store current rotation of canvas in field variable , on each update of data use objectanimator smoothly update value of current rotation of canvas new value. sure invalidate view on each animation frame. can read more animations of properties , objectanimator here: property animation


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -