【发布时间】:2015-07-24 10:07:04
【问题描述】:
我有什么
我有一个箭头图像(如左图)。当用户点击它时,它应该会随着动画旋转 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) {
}
});
}
问题
我看到动画效果很好,但是在设置图像时有一点闪烁。可能是因为动画结束和图片设置的时间差。
如何消除此闪烁问题?您有更好的方法来做到这一点吗?
【问题讨论】:
-
以编程方式旋转动画。 RotateAnimation : clockwise/anticlockwise
标签: android android-animation android-imageview image-rotation