0

I was making this simple and cool looking animation. And using this question - How to spin an android icon on its center point? I got my icon to rotate. But after the rotation I wish to move the image view upwards. How can I achieve this?

I'm using this code to move the imageview upwards.

  TranslateAnimation animation = new TranslateAnimation(0, 0, 0, -700);
  animation.setDuration(1*1500);
  animation.setRepeatCount(0);
  ImageButton logo_icon_two = (ImageButton) findViewById(R.id.logo_icon);
  logo_icon_two.startAnimation(animation);

The problem is that when I add the code, the image view moves up but then goes back to the spot it was in, also the rotation animation stops. My full class below -

public class WelcomeActivity extends Activity {

    private static final float ROTATE_FROM = 0.0f;
    private static final float ROTATE_TO = -10.0f * 360.0f;// 3.141592654f * 32.0f;

     /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.welcome_activity);

        ImageButton logo_icon = (ImageButton) findViewById(R.id.logo_icon);

      RotateAnimation r; // = new RotateAnimation(ROTATE_FROM, ROTATE_TO);
      r = new RotateAnimation(ROTATE_FROM, ROTATE_TO, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
      r.setDuration((long) 1*1500);
      r.setRepeatCount(0);
      logo_icon.startAnimation(r);

      TranslateAnimation animation = new TranslateAnimation(0, 0, 0, -700);
      animation.setDuration(1*1500);
      animation.setRepeatCount(0);
      ImageButton logo_icon_two = (ImageButton) findViewById(R.id.logo_icon);
      logo_icon_two.startAnimation(animation);
    }
}

Question is, how can I make it that, when opening app. the image rotates and then stops, and then the image is then moved up.

Community
  • 1
  • 1
Robin
  • 577
  • 1
  • 7
  • 13

1 Answers1

1

You have to call setFillAfter(true) method for both your animations, and if necessary, change the layoutparams of imageview after animation end then invalidate once.

Pankaj Deshpande
  • 502
  • 2
  • 5
  • 15
  • Thank you, but the second animation always starts? How can I make it so that the first animation takes place then it waits a second then the second animation takes place? – Robin Jun 04 '14 at 07:57
  • To achieve this, you have to add animation listener to your first animation, and override all it's methods. in onAnimationEnd method of first animation's animation listener, start second animation and you can add a delay to start second animation using this method: [setStartOffset](http://developer.android.com/reference/android/view/animation/Animation.html#setStartOffset(long)) – Pankaj Deshpande Jun 05 '14 at 04:28