Search code examples
androidrotationtranslate-animation

Rotate wont work after translate


I have programatically translated an image. Later, in my code, I attempt to rotate the image about its own center. But the rotate is rotating the image around its original placement before it was translated. I have commented out the translate portion of code and everything works fine, the image rotates around its on center. But when I translate it first, the rotate doesnt take the new position into account. What do I need to do?

View v;
animation anim = AnimationUtils.loadAnimation(getApplication(),R.anim.slide_in_up);
v.setTranslationY(#);
v.startAnimation(anim);

xml below:

<set xmlns:android="http://schemas.android.com/apk/res/android">
 <rotate
  android:fromDegrees="-360.0"
  android:toDegrees="0.0"
  android:pivotX="50%"
  android:pivotY="50%"
  android:duration="1000" />
</set>

Solution

  • the answer is to rotate the image first and then translate it. i was doing it the other way which is why it was not rotating about the center.