我想每次旋轉一次imageView 10次,imageView會隨機加載可繪製資源中的圖像。例如:有6個圖像,如img1到img6。我不喜歡這樣的代碼,但它不工作重複動畫時更改圖片
public void clockwise(View view){
for (int i=1; i<=6; i++){
ImageView image = (ImageView)findViewById(R.id.imageView);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.clockwise);
animation.setRepeatCount(10);
int max=6, min=1;
int randNum = min + (int)(Math.random()*((max-min)+1));//
if (randNum==1) image.setImageDrawable(getResources().getDrawable(R.drawable.die1));
else if (randNum==2) image.setImageDrawable(getResources().getDrawable(R.drawable.die2));
else if (randNum==3) image.setImageDrawable(getResources().getDrawable(R.drawable.die3));
else if (randNum==4) image.setImageDrawable(getResources().getDrawable(R.drawable.die4));
else if (randNum==5) image.setImageDrawable(getResources().getDrawable(R.drawable.die5));
else if (randNum==6) image.setImageDrawable(getResources().getDrawable(R.drawable.die6));
image.startAnimation(animation);
}
它只是加載,我在XML文件中設置爲10次重複