I’d like to assign 28 different rotation animations to 28 different views, and start them when activity starts. Animations should all have random startOffset and Duration.
I’ve tried with this code, but it seems that all the animations have the same values anyway.
RotateAnimation rotate = new RotateAnimation(0.0f, 360.0f,
Animation.RELATIVE_TO_SELF, 0.9f, Animation.RELATIVE_TO_SELF, 0.5f);
ImageView imageView;
Random r = new Random();
int delayOffset = 0;
int rotationDuration = 200;
for (int i = 0; i < ids.length; i++) {
rotate.reset();
imageView = (ImageView) findViewById(ids[i]);
imageView.clearAnimation();
delayOffset = r.nextInt(500 - 0);
rotationDuration = r.nextInt(10000 - 200) + 200;
rotate.setStartOffset(delayOffset);
rotate.setDuration(rotationDuration);
imageView.startAnimation(rotate);
}
What am I doing wrong ?
you are using the exact same instance of the animation , so all of the views are starting it with the most updated value .
you should create a totally new animation for each of the views.