How to animate an icon for expand/collapse view?
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;
For another solution, if you want it to rotate 180° every time the view is pressed then try this instead,
rotationAngle = rotationAngle == 0 ? 180 : 0; //toggle
mExpandArrow.animate().rotation(rotationAngle).setDuration(500).start();
Just define rotationAngle initially as,
int rotationAngle = 0;