I have this icon:

And when I click on my item in the list, I want it to rotate 180 °. When I press again, I want him to turn another 180 ° so that he returns to its original position.
First I tried:
view.animate().rotation(180).setDuration(500).start();
But it only works 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 at the same time, the animation always starts with an arrow pointing down and rotating up, even if the arrow is already pointing up.
So how can I make this work?
source
share