0

I have a problem with tween animation in android , I try to move an ImageView item from center of screen to top of screen but after end of transform ImageView returns to first position! I use this code:

   <?xml version="1.0" encoding="utf-8"?>
       <translate 
        xmlns:android="http://schemas.android.com/apk/res/android"
         android:interpolator="@android:anim/bounce_interpolator"
         android:fromYDelta="0%"
         android:toYDelta="-1500%"
         android:duration="3000"
         android:startOffset="3000">
         </translate>

private void RunAnimations() {

    Animation animation = AnimationUtils.loadAnimation(this, R.anim.move_up_maxname);
    animation.reset();
    ImageView maxName = (ImageView) findViewById(R.id.imageView1);
    maxName.clearAnimation();
    maxName.startAnimation(animation);
}

Can anyone help me?
Thanks

Caner
  • 57,267
  • 35
  • 174
  • 180
mahdi
  • 16,257
  • 15
  • 52
  • 73

3 Answers3

3

You need to take a look at setFillAfter:

If fillAfter is true, the transformation that this animation performed will persist when it is finished.

njzk2
  • 38,969
  • 7
  • 69
  • 107
2

Use AnimationListener and in onAnimationEnd() change the position of ImageView(Last point).

animation.setAnimationListener(new AnimationListener() {

   public void onAnimationStart(Animation anim)
   {};

   public void onAnimationRepeat(Animation anim)
   {};

   public void onAnimationEnd(Animation anim)
   {
     //Change imageview position using LayoutParameters
   };
});                     
Mohammed Azharuddin Shaikh
  • 41,633
  • 14
  • 96
  • 115
2

add line animation.setFillAfter(true);

jay
  • 292
  • 1
  • 11