尝试再次旋转视图时,Android RotateAnimation会使视图闪烁

时间:2014-12-22 10:56:05

标签: android animation rotation floating-action-button

我正在尝试实现一个浮动动作按钮,一个简单的加号,在选择时应旋转45度,再次按下时再旋转。旋转到45度效果很好,但是当我再次按下时,图像会闪烁到原始位置。如何防止闪烁?

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);
}

0 个答案:

没有答案