0

我正在尝试实现一个浮动操作按钮,一个简单的加号,它应该在选择时旋转 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);
}
4

0 回答 0