开发者

Android image moving animation problem

开发者 https://www.devze.com 2023-03-31 03:17 出处:网络
i used following code to animate a image it works fine but while animating the image looks little jumping rather than smooth moving.(It looks like moving but not quite smooth. it stops a while in betw

i used following code to animate a image it works fine but while animating the image looks little jumping rather than smooth moving.(It looks like moving but not quite smooth. it stops a while in between) Can Any one find the problem in code?

 class AnimationLoop implements Runnable
{
        public void run()
    {
        while(true)
        {
      开发者_开发知识库      while(running)
            {                           
                try
                {

                    Thread.sleep(30);

                }
                catch(InterruptedException ex) {}
        } 
     } 
   counter+=1;
   updatePosition(0);
   main.postInvalidate(); //main is  type panel   

 }
 private synchronized void  updatePosition(int index) {
        mYPositions[index]-=2;         // animate from bottom to top
        mXPositions[index]-=2;
}


    @Override 
    protected void onDraw(Canvas canvas)
    {  

             canvas.drawBitmap(balloonSet.get(0), mXPositions[0], mYPositions[0],null);  
    }


The smoothness of your animation will depend on the change in coordinates and the time it stays at a single coordinate. If you want to move the animation at same speed but a little smooother, then reduce the time and unit change by same ratio.

For example: Your case reduce by 50%. That will make x and y position to be deducted by 1 and the sleep time will be 15ms.

This might help how to animate bitmaps

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号