2011-05-24 153 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) { } 
     });