Multiple animations to an image view in different time

189 views Asked by At

I want to animate an imageview in a spiral path while rotating. I have used an animation set and added these animations as the first step so that imageview will move to right first and then to below. (Width and height is the width and height of the screen which I have taken using widthPixels and heightPixels methods in DisplayMetric type attribute)

        animation1 = new TranslateAnimation(Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, width-180,
        Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, 0.0f);
        animation1.setInterpolator(new DecelerateInterpolator());
        animation1.setDuration(5000);

        RotateAnimation ranim = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); //, 200, 200); // canvas.getWidth() / 2, canvas.getHeight() / 2);
        ranim.setDuration(5000);
        ranim.setInterpolator(new DecelerateInterpolator());

        animation2 = new TranslateAnimation(Animation.ABSOLUTE, width - 180, Animation.ABSOLUTE, width - 180,
                Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, height - 300);
        animation2.setInterpolator(new DecelerateInterpolator());
        animation2.setDuration(7000);
        animation2.setStartOffset(5000);

        RotateAnimation ranim2 = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); //, 200, 200); // canvas.getWidth() / 2, canvas.getHeight() / 2);
        ranim2.setDuration(7000);
        ranim2.setInterpolator(new DecelerateInterpolator());
        ranim2.setStartOffset(5000);

When I run this only animation2 + ranim2 is exectuing where the imageview will move from the top right corner of the screen to bottom right corner of the screen while rotating. Can someone tell me how to do this animation? Thankyou :)

1

There are 1 answers

3
gunjan luthra On

You can use AnimationSet for this.