2015-02-04 1 views
0

I 앱이 시작될 때 (3)이 재생 될 애니메이션을 번역해야 - 나는, 임의의 순서로 먼저 반드시 첫 번째를 위의 3을 시작하려는Android에서 무작위 순서로 애니메이션을 번역하는 방법?

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); 

.

하루 종일 사라졌으며 여전히 해결책을 찾을 수 없습니다. 어떻게 그것을 달성하기위한 지침?

답변

1

당신은 자바 random 번호를 생성하고 이것은

Random random = new Random(); 
int num = 3; 

switch(random.nextInt(num)) { 
    case 0: 
     animateFirst(); 
      break; 
    case 1: 
      animateSecond(); 
      break; 
    case 2: 
     animateThird(); 
      break; 

} 
+0

을 수정하지만, 임의의 순서라고 할 수 있습니다. 나는 그것의 3,2,1 또는 2,1,3을 좋아한다라고 생각한다. 내 생각은 –

+0

어떻게 3 개의 가능한 번호를 무작위로 바꿀 것입니까? 3의 확률은 1, 3의 확률은 3, 3의 확률은 3입니다. –

+0

도움이 될 경우 대답을 수락하십시오. –

0

내가 가진 하나의 방법을 전환 할, 코드, @Murtaza 후세인

switch(random.nextInt(num)) { 
     case 0: 
      animateFirst(); 
      animateSecond(); 
      animateThird(); 
       break; 
     case 1: 
       animateSecond(); 
       animateFirst(); 
       animateThird(); 
       break; 
     case 2: 
      animateFirst(); 
      animateThird(); 
      animateSecond(); 
       break; 

    } 
관련 문제