What I Have
I have an arrow image (like the left one). Whe
Verified Code: (You can follow my solution)
imageView.setImageResource(R.drawable.ic_arrow_up);
boolean up = true;
if (!up) {
up = true;
imageView.startAnimation(animate(up));
} else {
up = false;
imageView.startAnimation(animate(up));
}
private Animation animate(boolean up) {
Animation anim = AnimationUtils.loadAnimation(this, up ? R.anim.rotate_up : R.anim.rotate_down);
anim.setInterpolator(new LinearInterpolator()); // for smooth animation
return anim;
}
drawable/ic_arrow_up.xml
anim/rotate_up.xml
anim/rotate_down.xml
I used that code. Because this will save the animation state:
android:fillAfter="true"
android:fillEnabled="true"