我想爲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