I have this icon:
And when i press my item in a listview i want it to rotate 180°. When i click again i want it to rotate another 180° so it get's to it's original position.
First i tried:
view.animate().rotation(180).setDuration(500).start();
But it only fires once. After that i tried:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true"
android:fillEnabled="true">
<rotate
android:duration="500"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="180" />
</set>
But with that the animation always starts with the arrow showing to the buttom and rotating to the top even if the arrow already shows to the top.
So how can i make that working?
User following code to click event of image:
ObjectAnimator anim = ObjectAnimator.ofFloat(v, "rotation",rotationAngle, rotationAngle + 180);
anim.setDuration(500);
anim.start();
rotationAngle += 180;
rotationAngle = rotationAngle%360;
and make rotationAngle a global variable:
int rotationAngle = 0;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With