Bhargav Thanki
Bhargav Thanki

Reputation: 4954

RotateAnimation behaves weird after changing the position of a View

I am using RotateAnimation to rotate the imageView to -30 degrees. And it works good. Now I change the position of the view by setting different values for X and Y. All good until now.

Now when I perform the same RotateAnimation again to this view after the position changed, it works weird (see the video link below) and I cannot find the reason. I have tried a lot but without success. It seems like related to the pivotX and pivotY after changing the position but I cannot find the actual cause.

Code for RotateAnimation

final RotateAnimation rotateAnim = new RotateAnimation(0f, -30f,
            RotateAnimation.RELATIVE_TO_SELF, 0.5f,
            RotateAnimation.RELATIVE_TO_SELF, 1f);
rotateAnim.setDuration(2000);
rotateAnim.setFillAfter(false);
ivFace.startAnimation(rotateAnim);

Code of changing the position of an imageview

ivFace.setX(300);
ivFace.setY(200);

Here I am posting the video also for better understanding https://www.youtube.com/watch?v=uVWlrTNDKCM

Upvotes: 2

Views: 63

Answers (1)

A Honey Bustard
A Honey Bustard

Reputation: 3493

Looks like the RotationAnimation is still rotating around the 'old' view position, probably because it is 'final' and thats why it is tied to the Views 'old' position the moment it is created. You could create a new RotationAnimation for every position change, which might solve the issue, although I would suggest using ViewPropertyAnimator and/or ObjectAnimator for both, translating your View to another position and rotating it.

Upvotes: 1

Related Questions