【问题标题】:Android image moving animation problemAndroid图像移动动画问题
【发布时间】:2011-11-03 09:04:45
【问题描述】:

我使用以下代码为图像设置动画效果很好,但是在设置动画时图像看起来很少跳跃而不是平滑移动。(看起来像移动但不太平滑。中间会停一段时间)任何人都可以找到问题在代码中?

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

【问题讨论】:

    标签: android android-animation translate-animation


    【解决方案1】:

    动画的流畅度取决于坐标的变化以及它在单个坐标上停留的时间。如果您想以相同的速度移动动画但更平滑一点,则以相同的比例减少时间和单位变化。

    例如:您的案例减少 50%。这将使 x 和 y 位置减 1,睡眠时间为 15ms。

    这可能有助于how to animate bitmaps

    【讨论】:

    • 我在答案中添加了一个链接。希望对您有所帮助。
    猜你喜欢
    • 2011-07-08
    • 2023-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多