Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get an imageview to rotate while translating in Android?

I am trying to make an imageview that rotates while sliding across the screen. I setup a rotate animation for 180 degrees, and it works by itself. I setup a translate animation and it works by itself. When I combine them I get an imageview that makes a big spiral. I would like the imageview to rotate around the center of the imageview while being translated.

        AnimationSet animSet = new AnimationSet(true);
        //Translate upwards and to the right.   
        TranslateAnimation anim =
            new TranslateAnimation(
                    Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, +80.0f,
                    Animation.ABSOLUTE, 0.0f, Animation.ABSOLUTE, -100.0f
                    );
            anim.setInterpolator(new DecelerateInterpolator()); 
            anim.setDuration(400);
            animSet.addAnimation(anim);

            //Rotate around center of Imageview
            RotateAnimation ranim = new RotateAnimation(0f, 180f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); //, 200, 200); // canvas.getWidth() / 2, canvas.getHeight() / 2);
            ranim.setDuration(400);
            ranim.setInterpolator(new DecelerateInterpolator());

            animSet.addAnimation(ranim);

            imageBottom.startAnimation(animSet);
like image 796
Ravedave Avatar asked Mar 26 '10 01:03

Ravedave


1 Answers

Well I guess I "rubber ducked" this one.

The order that the animations are applied matters. I switched the order from translate/rotate to rotate/translate and it works.

like image 71
Ravedave Avatar answered Sep 26 '22 03:09

Ravedave