ObjectAnimator|ObjectAnimator 动画后 恢复初始状态
位移后 恢复状态:mMiddleAvatar.setTranslationX(0);
改变透明度之后恢复:mMiddleAvatar.setAlpha(1.0f);
旋转后恢复:mMiddleAvatar.setRotation(0);
缩放后恢复:
mMiddleAvatar.setScaleX(1.0f); mMiddleAvatar.setScaleY(1.0f);
取消 AnimatorSet 动画:
if (mLastAnimatorSet != null) { mLastAnimatorSet.cancel(); } 这种取消会走 onAnimationEnd 回调
所以自定义一个AnimatorListenerAdapter
public abstract class CancelAnimatorListenerAdapter extends AnimatorListenerAdapter { private boolean mCanceled = false; @Override public void onAnimationCancel(Animator animation) { super.onAnimationCancel(animation); mCanceled = true; }public boolean isCanceled() { return mCanceled; } }
使用:
ObjectAnimator rightAvatarScaleXAnimator = ObjectAnimator.ofFloat(mRightAvatar, "scaleX", 1.03f, 1.0f); ObjectAnimator rightAvatarScaleYAnimator = ObjectAnimator.ofFloat(mRightAvatar, "scaleY", 1.03f, 1.0f); mLastAnimatorSet = new AnimatorSet(); mLastAnimatorSet.play(rightAvatarScaleXAnimator).with(rightAvatarScaleYAnimator); mLastAnimatorSet.setDuration(100); mLastAnimatorSet.start(); mLastAnimatorSet.addListener(new CancelAnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); if (isCanceled()) {return; } if (mMiddleAvatar == null) { return; } mRightAvatar.setTranslationX(0); mRightAvatar.setAlpha(0.0f); mRightAvatar.setScaleX(1.0f); mRightAvatar.setScaleY(1.0f); mMiddleAvatar.setAlpha(1.0f); startMatchTipsAnimation(); } });
【ObjectAnimator|ObjectAnimator 动画后 恢复初始状态】
推荐阅读
- 开学第一天(下)
- 爱就是希望你好好活着
- 三十年后的广场舞大爷
- Y房东的后半生14
- 七年之痒之后
- MediaRecorder前后摄像头同时录像
- 基于微信小程序带后端ssm接口小区物业管理平台设计
- 迷失的世界(二十七)
- 上班后阅读开始变成一件奢侈的事
- 你有婚内虐待行为吗()