2011-08-25 118 views
0

我使用下面的代码来动画化一个图像,它的工作正常,但动画图像看起来很少跳跃,而不是平滑移动(它看起来像移动,但不是很光滑,它会停止一段时间)Can任何人在代码中发现问题?Android图像移动动画问题

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); 
    } 

回答

0

动画的平滑度将取决于坐标的变化以及它停留在单个坐标上的时间。如果您想要以相同的速度移动动画,但要稍微平滑一些,请按相同的比例缩短时间和单位更改。

例如:你的情况下降50%。这将使x和y的位置被扣1,并且睡眠时间将是15ms。

这可能有助于how to animate bitmaps

+0

我仍然可以看到..其像跳跃.. – vnshetty

+0

我已经添加了答案的链接。希望能帮助到你。 – Ronnie