MePo
MePo

Reputation: 1074

Translating(Animation) multiple Images with delay on Android

I want to make a marquee of images(making them move from right to left with empty space between) I tried to make multiple Animations with different starting points, as I taught it might work (but it didn't only one picture animates).

Here is my code so far:

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

Next thing that came to my mind is using Threads, but if I am correct only one Animation can run. I also taught of making one image from these three (but there will be white background I want it to be transparent). Any help is appreciated.

Edit: Tried also with

animation.setStartOffset(1000);

Only the first one starts

Upvotes: 0

Views: 1607

Answers (1)

pooja
pooja

Reputation: 71

You are using same animation variable..Try this:

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

Upvotes: 1

Related Questions