如何在 Android 中以随机顺序启动翻译动画?
How to start Translate Animation in random order in Android?
我有 3 个翻译动画要在应用程序启动时播放 -
Animation animation = new TranslateAnimation(0, 0, -1500, 1500);
animation.setDuration(1000);
animation.setFillAfter(false);
myimage.startAnimation(animation);
animation.setRepeatCount(Animation.INFINITE);
Animation animation2 = new TranslateAnimation(0, 0, -1000, 1000);
animation2.setDuration(1000);
animation2.setFillAfter(false);
myimage2.startAnimation(animation2);
animation2.setRepeatCount(Animation.INFINITE);
Animation animation3 = new TranslateAnimation(0, 0, -500, 500);
animation3.setDuration(1000);
animation3.setFillAfter(false);
myimage3.startAnimation(animation3);
animation3.setRepeatCount(Animation.INFINITE);
以上3个我想随机开始,不一定是第一个在前
一整天过去了,我仍然找不到解决办法。
关于如何实现它的任何指示?
您可以在 java 中生成 random
数字并进行切换
Random random = new Random();
int num = 3;
switch(random.nextInt(num)) {
case 0:
animateFirst();
break;
case 1:
animateSecond();
break;
case 2:
animateThird();
break;
}
这是我得到的一种方法,修改你的代码,@Murtaza Hussain
switch(random.nextInt(num)) {
case 0:
animateFirst();
animateSecond();
animateThird();
break;
case 1:
animateSecond();
animateFirst();
animateThird();
break;
case 2:
animateFirst();
animateThird();
animateSecond();
break;
}
我有 3 个翻译动画要在应用程序启动时播放 -
Animation animation = new TranslateAnimation(0, 0, -1500, 1500);
animation.setDuration(1000);
animation.setFillAfter(false);
myimage.startAnimation(animation);
animation.setRepeatCount(Animation.INFINITE);
Animation animation2 = new TranslateAnimation(0, 0, -1000, 1000);
animation2.setDuration(1000);
animation2.setFillAfter(false);
myimage2.startAnimation(animation2);
animation2.setRepeatCount(Animation.INFINITE);
Animation animation3 = new TranslateAnimation(0, 0, -500, 500);
animation3.setDuration(1000);
animation3.setFillAfter(false);
myimage3.startAnimation(animation3);
animation3.setRepeatCount(Animation.INFINITE);
以上3个我想随机开始,不一定是第一个在前
一整天过去了,我仍然找不到解决办法。 关于如何实现它的任何指示?
您可以在 java 中生成 random
数字并进行切换
Random random = new Random();
int num = 3;
switch(random.nextInt(num)) {
case 0:
animateFirst();
break;
case 1:
animateSecond();
break;
case 2:
animateThird();
break;
}
这是我得到的一种方法,修改你的代码,@Murtaza Hussain
switch(random.nextInt(num)) {
case 0:
animateFirst();
animateSecond();
animateThird();
break;
case 1:
animateSecond();
animateFirst();
animateThird();
break;
case 2:
animateFirst();
animateThird();
animateSecond();
break;
}