我的现状
我有一个箭头图片(如左图)。当用户点击它时,它应该以180度的动画旋转,并且看起来像右图。
我做了什么
private void rotate(float degree, final int toggleV) {
final RotateAnimation rotateAnim = new RotateAnimation(0.0f, degree,
RotateAnimation.RELATIVE_TO_SELF, 0.5f,
RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotateAnim.setDuration(500);
toggle.startAnimation(rotateAnim);
rotateAnim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
if (toggleV == 1)
toggle.setImageResource(R.drawable.toggle_up);
else
toggle.setImageResource(R.drawable.toggle_down);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
问题
我发现动画运行得很好,但是在设置图像时会有一点闪烁。可能是由于动画结束和图像设置之间的时间差异导致的。
我该如何解决这个闪烁问题?您有更好的方法来做到这一点吗?