Pawel Jezierski Pawel Jezierski - 4 months ago 7
Android Question

Animating imageview broken if it's started again before one cycle finishes

I've got an ImageView that I rotate with animation by 180 degrees with OnClickListener. If it's triggered very fast (before one animation finishes) the animation bugs out and leaves the View at weird angle (for example rotated 47 degrees versus basic state).

How to prevent next animation before current one finishes or how to deal with it in another way?

bankExpandArrow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (totalText.getVisibility() == View.GONE) {
totalText.setVisibility(View.VISIBLE);;
bankExpandArrow.animate().rotationBy(180f).start();
}
else {
totalText.setVisibility(View.GONE);
bankExpandArrow.animate().rotationBy(180f).start();
}
}
});

Answer

try using rotation instead of rotationBy