2012-06-26 2 views
0

서로 다른 시간 간격으로 서로 다른 객체 세트를 차례로 애니메이트하는 방법은 무엇입니까?Android : 다른 시간대의 다른 오브젝트에 애니메이션을 적용하는 방법은 무엇인가요?

자바 코드 :

ImageButton home = (ImageButton)findViewById(R.id.homeicon); 
ImageButton settings = (ImageButton)findViewById(R.id.settingsicon); 

Animation alpha_anim = AnimationUtils.loadAnimation(this, R.anim.alpha); 
home.startAnimation(alpha_anim); 
settings.startAnimation(alpha_anim); 

애니메이션 파일 :

<?xml version="1.0" encoding="utf-8"?> 
<alpha 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:fromAlpha="0.0" 
android:toAlpha="0.9" 
android:duration="8000" /> 

이 사람이 나를 도울 수 있습니까?

답변

1

의 경로를 이동해야 할 수도없는 다음 경우이 충분히 정확하지 않을 수 있다는 것을 깨닫게하시기 바랍니다 , 두 번째 레이아웃에서 애니메이션을 시작하고 싶었습니다. 당신이 코드를 사용할 수있는 다른 후 하나를 수행하려면

그래서 나는이

Handler handler = new Handler(); // create Handler object 
handler.post(homeRun); 
Runnable homeRun = new Runnable() { // create runnable to start home anim 
    public void run() { 
     home.startAnimation(alpha_anim); 
     handler.postDelayed(settingsRun, 1000); // start setting anim after the time the home takes to animate 
    } 
}; 

Runnable setingsRun = new Runnable() { // runnable to start settings anim 
    public void run() { 
     settings.startAnimation(alpha_anim); 
    } 
}; 
1

두 번째 애니메이션에 지연 시간을 추가 할 수 있습니다. 당신이 필요로 당신은 내가 그 마무리하자마자 먼저 레이아웃을 애니메이션과해야 할 하나 개의 화면을 가지고 있던 AnimationListener

home.startAnimation(alpha_anim); 
alpha_anim.setStartOffset(8000); 
settings.startAnimation(alpha_anim); 
+0

고마워요! 그것은 나를 위해 완벽하게 작동합니다! – luiscosta

0

처럼, 그렇게 그 시간에 handler을 사용했다. 리스너를 사용하면 애니메이션이 끝났음을 확신 할 수 있습니다.

animation.setDuration(8000); 
    animation.setAnimationListener(new AnimationListener() { 

     @Override 
     public void onAnimationEnd(Animation animation) { 
      animation.setDuration(6000); 
           animation.setAnimationListener(null); 
      settings.startAnimation(animation); 
     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 

     } 

     @Override 
     public void onAnimationStart(Animation animation) { 
     } 

    }); 
    home.startAnimation(alpha_anim); 
+0

무엇을 권하고 싶습니다 : http://stackoverflow.com/questions/18899280/multiple-xml-animation-is-not-working – Si8

관련 문제