【问题标题】:Translating(Animation) multiple Images with delay on Android在Android上延迟翻译(动画)多个图像
【发布时间】:2014-07-31 01:36:55
【问题描述】:

我想制作一组图像(让它们从右向左移动,中间有空白)动画)。

到目前为止,这是我的代码:

ImageView img_animation = (ImageView) findViewById(R.id.imageView1);
ImageView img_animation2 = (ImageView) findViewById(R.id.imageView2);
ImageView img_animation3 = (ImageView) findViewById(R.id.imageView3);

img_animation.setImageResource(R.drawable.num1);
img_animation2.setImageResource(R.drawable.num2);
img_animation2.setImageResource(R.drawable.num3);

        TranslateAnimation animation = new TranslateAnimation(50.0f, -300.0f,
                0.0f, 0.0f);         
        animation.setDuration(20000); 
        animation.setRepeatCount(10);

                TranslateAnimation animation2 = new TranslateAnimation(100.0f, -300.0f,
                0.0f, 0.0f);         
        animation.setDuration(20000); 
        animation.setRepeatCount(10); 

                TranslateAnimation animation3 = new TranslateAnimation(150.0f, -300.0f,
                0.0f, 0.0f);         
        animation.setDuration(20000); 
        animation.setRepeatCount(10); 

        img_animation.startAnimation(animation); 
        img_animation2.startAnimation(animation2);
        img_animation3.startAnimation(animation3);

接下来我想到的是使用线程,但如果我是正确的,只有一个动画可以运行。我还教过从这三个中制作一张图像(但是会有白色背景,我希望它是透明的)。任何帮助表示赞赏。

编辑:也尝试过

animation.setStartOffset(1000);

只有第一个开始

【问题讨论】:

  • 您写道,您使用了多个起点不同的动画,但是您只使用了一个对所有图像都相同的动画...所以...是的...只需创建 3 个动画并设置启动延迟到不同的值。
  • 我做了,但只有第一个开始

标签: android image translate-animation


【解决方案1】:

您正在使用相同的动画变量..试试这个:

    TranslateAnimation animation = new TranslateAnimation(50.0f, -300.0f,
            0.0f, 0.0f);         
    animation.setDuration(20000); 
    animation.setRepeatCount(10);

     TranslateAnimation animation2 = new TranslateAnimation(100.0f, -300.0f,
            0.0f, 0.0f);         
    animation2.setDuration(20000); 
    animation2.setRepeatCount(10); 

     TranslateAnimation animation3 = new TranslateAnimation(150.0f, -300.0f,
            0.0f, 0.0f);         
    animation3.setDuration(20000); 
    animation3.setRepeatCount(10); 

    img_animation.startAnimation(animation); 
    img_animation2.startAnimation(animation2);
    img_animation3.startAnimation(animation3);

【讨论】:

    猜你喜欢
    • 2023-03-20
    • 1970-01-01
    • 2012-07-19
    • 2014-08-16
    • 1970-01-01
    • 2012-04-13
    • 2011-09-18
    • 1970-01-01
    • 2015-06-13
    相关资源
    最近更新 更多