For example: The view will animate, it will wait for 4 seconds as it is, again it will animate and it will wait for 2 seconds and then again 4 and 2 secs continously. I tried using scheduleAtFixedRate method from Timer class. Its working for any one time interval, how do I make it work for 4 and 2 seconds continously. Thanks
Asked
Active
Viewed 155 times
-1
-
Always make it 2 secs, and store a boolean value that you can toggle, and sleep the thread for another 2 seconds when it is true? – OneCricketeer Mar 31 '16 at 19:49
-
You can achieve that using the Random class – Eury Pérez Beltré Mar 31 '16 at 19:52
1 Answers
0
Alternating the start offset can be achieved by using an animation listener, changing its offset on animation end, and restarting the animation.
Animation a = //initialize here
a.setStartOffset(2000);
a.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
a.setStartOffset(a.getStartOffset() == 2000 ? 4000 : 2000);
a.start();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
a.start();

Dmitri Timofti
- 2,428
- 1
- 22
- 25