Reputation: 1107
In my android app, I want to apply an animation
on some imageViews
with implementing delay. When the 1st imageView
is animated 50%, i want to start animation
of the second imageView
and goes on like this.
I used Thread.sleep()
method for this.
public void showImage() throws IOException, InterruptedException{
final Animation anim = AnimationUtils.loadAnimation(Home.this,R.anim.myanimation);
image_1.setImageUrl(links[0]);
image_2.setImageUrl(links[1]);
image_3.setImageUrl(links[2]);
image_4.setImageUrl(links[3]);
image_5.setImageUrl(links[4]);
image_6.setImageUrl(links[5]);
image_7.setImageUrl(links[0]);
image_8.setImageUrl(links[1]);
//System.out.println("me");
image_1_layer.setAnimation(anim);
Thread.sleep(5000);
image_2_layer.setAnimation(anim);
Thread.sleep(5000);
image_3_layer.setAnimation(anim);
Thread.sleep(5000);
image_4_layer.setAnimation(anim);
Thread.sleep(5000);
image_5_layer.setAnimation(anim);
Thread.sleep(5000);
image_6_layer.setAnimation(anim);
Thread.sleep(5000);
image_7_layer.setAnimation(anim);
Thread.sleep(5000);
image_8_layer.setAnimation(anim);
Thread.sleep(5000);
}
But when it run the app, it delay before starting any animation
and then paralally animate all the imageViews
. how can I start to animate the next imageView
after 5 seconds of the previous imageView
's animation
?
I called the above showImage()
method from the override method onPostExecute()
.
Upvotes: 1
Views: 1002
Reputation: 15774
Using Thread.sleep
is an incorrect way of achieving what you want. You should take a look at the Animation
class, specifically the setStartTime
.
You can either construct different animation objects with different (compounded) start times and apply all of them to the views or you can listen to animation events using setAnimationListener
Upvotes: 3