2011-05-24 155 views
0

我試圖使用動畫將圖像從一個地方移動到另一個地方,但在移動它回到原始位置之後,如何將其停止到移動的位置本身。Android動畫

+0

顯示代碼,請! – 2011-05-24 12:57:44

回答

0

this blog post for a solution

// first set the view's location to the end position 
view.setLayoutParams(...); // set to (x, y) 

// then animate the view translating from (0, 0) 
TranslationAnimation ta = new TranslateAnimation(-x, -y, 0, 0); 
ta.setDuration(1000); 
view.startAnimation(ta); 
1

讓在動畫的最後一個地方的形象,試試這個:

TranslationAnimation ta = new TranslateAnimation(fromX, toX, 0, 0); 
ta.setDuration(1000); 
ta.setFillAfter(true); // this will let the image in the last place of the Animation 
imageView.startAnimation(ta); 
0

我相信你應該已經找到了答案(我只是...所以我張貼給其他人)。 Android似乎已經正式轉向了名爲「Property Animation」的新動畫框架。自從Honeycomb(3.0)以來,這已經可用。這將基本上解決您的問題,因爲它動畫的實際屬性值。

開發指南:一個動畫完成 http://developer.android.com/guide/topics/graphics/prop-animation.html

1

後,使用方法setFillAfter(真),使最後的動畫狀態仍然存在:

如果fillAfter是真實的,轉型,這執行完成後的動畫將保持不變。

Animation.setFillAfter/Before - Do they work/What are they for?

如果您需要做更具體的東西,你也可以設置一個動畫監聽器,並在動畫的最後移動你的對象:

animation1.setAnimationListener(new AnimationListener() { 
      @Override 
      public void onAnimationStart(Animation animation) { 
      } 

      @Override 
      public void onAnimationEnd(Animation animation) { 
       //change according to your needs 
       myView.setX(0); 
      } 

      @Override 
      public void onAnimationRepeat(Animation animation) { } 
     });