我想为28个不同的视图分配28个不同的旋转动画,并在活动开始时启动它们。动画应该都有随机的startOffset和Duration。 我试过这段代码,但似乎所有的动画都有相同的值。在多个ImageView上旋转动画
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);
}
我在做什么错?
尝试在您的for循环中创建一个RotateAnimation的新实例 – L7ColWinters