How to stop an animation (cancel() does not work)

后端 未结 7 1050
轮回少年
轮回少年 2020-11-29 16:52

I need to stop a running translate animation. The .cancel() method of Animation has no effect; the animation goes until the end anyway.

How

7条回答
  •  时光取名叫无心
    2020-11-29 17:15

    To stop animation you may set such objectAnimator that do nothing, e.g.

    first when manual flipping there is animation left to right:

    flipper.setInAnimation(leftIn);
    flipper.setOutAnimation(rightOut);
    

    then when switching to auto flipping there's no animation

    flipper.setInAnimation(doNothing);
    flipper.setOutAnimation(doNothing);
    
    doNothing = ObjectAnimator.ofFloat(flipper, "x", 0f, 0f).setDuration(flipperSwipingDuration);
    

提交回复
热议问题