Closed LiveSalton closed 5 years ago
ViewAnimator viewAnimator = ViewAnimator.animate(view).scale(1, 1.05f, 1).duration(3000)
.repeatCount(-1)
viewAnimator.start();
add method in ViewAnimator:
public void pause() {
if (this.animatorSet != null) {
if (Build.VERSION.SDK_INT >= 19) {
this.animatorSet.pause();
}
} else if (this.prev != null) {
this.prev.pause();
}
}
public void resume() {
if (this.animatorSet != null) {
if (Build.VERSION.SDK_INT >= 19) {
this.animatorSet.resume();
}
} else if (this.prev != null) {
this.prev.resume();
}
}
when onPause/onResume/onDestroy, try this:
viewAnimator.pause();
viewAnimator.resume();
viewAnimator.cance();
I don't know whether this can be solved.
如果通过pause、resume、cance可以解决内存泄露问题,那么,可以在ViewAnimator里加一个方法来自动维护生命周期,如:
public ViewAnimator attachLifecycle(LifecycleOwner owner) {
owner.getLifecycle().addObserver(this);
return this;
}
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
public void onAny(LifecycleOwner source, Lifecycle.Event event) {
if (event == Lifecycle.Event.ON_RESUME) {
resume();
} else if (event == Lifecycle.Event.ON_PAUSE) {
pause();
} else if (event == Lifecycle.Event.ON_DESTROY) {
cance();
source.getLifecycle().removeObserver(this);
}
}
好的,非常感谢你的方法。我已经处理好内存泄漏的问题。
好的,非常感谢你的方法。我已经处理好内存泄漏的问题。
老铁,你是怎么处理的?
泄漏怎么处理的?
my code is :
how can i release this anim??