I'm trying to implement a floating action button, a simple plus sign which should rotate 45 degrees on selection and rotate back when pressed again. Rotating to 45 degrees works well, but when I press again the image flickers to the original position. How can I prevent the flickering?
public void rotateImageView(final View img, boolean makeRotation) {
final float rotated = 45.0f;
final float notRotated = 0.0f;
final float rotTo;
final float rotFrom;
if(makeRotation) {
rotFrom = rotated;
rotTo = notRotated;
}
else {
rotFrom = notRotated;
rotTo = rotated;
}
RotateAnimation rotAnim = new RotateAnimation(rotFrom, rotTo,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
0.5f);
rotAnim.setDuration(200);
rotAnim.setFillBefore(true);
rotAnim.setFillAfter(true);
mAdd.startAnimation(rotAnim);
}