2014-01-24 62 views

回答

2

你可以連續動畫編程由animationSet的手段,然後通過AnimationListeners的方式添加任何你想要的結尾。

AnimationSet animationSet= new AnimationSet(); 

TranslateAnimation a = new TranslateAnimation(
     Animation.ABSOLUTE,FROM_X, Animation.ABSOLUTE,FROM_Y, 
     Animation.ABSOLUTE,TO_X, Animation.ABSOLUTE,TO_Y); 
a.setDuration(DURATION); 
a.setFillAfter(true); 
animationSet.addAnimation(a); 

TranslateAnimation b = new TranslateAnimation(
     Animation.ABSOLUTE,TO_X, Animation.ABSOLUTE,TO_Y, 
     Animation.ABSOLUTE,TO_X2, Animation.ABSOLUTE,TO_Y2); 
b.setDuration(DURATION2); 
b.setFillAfter(true); 
b.setStartOffset(DURATION); 
animationSet.addAnimation(b); 


//add all the animations that you need, having everyone starting in the position and the time where the last one ends. 
//Then add a listener to last animation, or to the animationset and write the code you need to run when everything is finished in the onAnimationEnd function 

animationSet.setAnimationListener(new Animation.AnimationListener() { 

     @Override 
     public void onAnimationEnd(Animation animation) { 

      //code to run when the animations are finished 
      //for instance, if you have some views in your layout that where hidden 
      View v= findViewById(R.id.YOUR_HIDDEN_VIEW; 
      v.setVisibility(View.VISIBLE); 


     } 


    }); 

如果你不知道如何開始的動畫,你havr給你打電話想動畫視圖的startAnimation方法。

THE_LOGO.startAnimation(animationSet); 

更新

在你編輯的問題,我可以看到,你只需要一個tranlation。所以它更容易。無論如何,你仍然可以使用動畫組,因爲第一個動畫可能是淡入淡出的alpha動畫。看看這裏http://developer.android.com/reference/android/view/animation/package-summary.html

0

使用animation listeneronAnimationEnd

+0

你能爲我提供使用的個例? – Oussa

+0

你需要提供你必須從頭開始的代碼 –

0

的posibilities的AnimationListener添加到您的動畫對象像下面

animation.setAnimationListener(new AnimationListener() { 

     @Override 
     public void onAnimationStart(Animation animation) { 
      //The Function which you want to do before the animation starts 

     } 

     @Override 
     public void onAnimationRepeat(Animation animation) { 
      //Functions to be executed each repeat of the animation 

     } 

     @Override 
     public void onAnimationEnd(Animation animation) { 
      //Functions to be executed at the end of animation 

     } 
    })