view.startAnimation(myAnimation)
我为某个视图设置了动画,一切正常。
但是如果视图进入
onPause
生命周期(activity、fragment、customView等..)并返回到onResume
动画将停止。
有没有办法让视图动画不自动停止?
试试这个,
private long animationPausedTime;
@Override
protected void onPause() {
super.onPause();
// Pause the animation and record the paused time
animationPausedTime = myAnimation.getStartTime() + myAnimation.getDuration() - System.currentTimeMillis();
view.clearAnimation();
}
@Override
protected void onResume() {
super.onResume();
// Resume the animation with remaining time
myAnimation.setStartTime(System.currentTimeMillis() - myAnimation.getDuration() + animationPausedTime);
view.startAnimation(myAnimation);
}