Commit abe1204a authored by mengcuiguang's avatar mengcuiguang

解决首页内存泄漏

parent 12f9ab31
...@@ -331,7 +331,9 @@ public class CircleProgress extends View { ...@@ -331,7 +331,9 @@ public class CircleProgress extends View {
} }
private void startAnimator(float start, float end, long animTime) { private void startAnimator(float start, float end, long animTime) {
mAnimator = ValueAnimator.ofFloat(start, end); if (mAnimator == null) {
mAnimator = ValueAnimator.ofFloat(start, end);
}
mAnimator.setDuration(animTime); mAnimator.setDuration(animTime);
mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override @Override
......
...@@ -123,7 +123,9 @@ public class CycleProgress extends View { ...@@ -123,7 +123,9 @@ public class CycleProgress extends View {
delta = delta == 0 ? 1 : delta; delta = delta == 0 ? 1 : delta;
mProgressWidth = (int) (progress * mViewWidth); mProgressWidth = (int) (progress * mViewWidth);
mAnimator = ValueAnimator.ofFloat(0, progress).setDuration(delta * DURATION); if (mAnimator == null) {
mAnimator = ValueAnimator.ofFloat(0, progress).setDuration(delta * DURATION);
}
mAnimator.setRepeatCount(ValueAnimator.INFINITE); mAnimator.setRepeatCount(ValueAnimator.INFINITE);
ValueAnimator.AnimatorUpdateListener mUpdateListener = animation -> { ValueAnimator.AnimatorUpdateListener mUpdateListener = animation -> {
...@@ -136,16 +138,13 @@ public class CycleProgress extends View { ...@@ -136,16 +138,13 @@ public class CycleProgress extends View {
} }
public void resumeAnim() { public void resumeAnim() {
if (mAnimator != null) { startAnim();
mAnimator.resume();
} else {
startAnim();
}
} }
public void pauseAnim() { public void pauseAnim() {
if (mAnimator != null) { if (mAnimator != null) {
mAnimator.pause(); mAnimator.cancel();
mAnimator.removeAllUpdateListeners();
} }
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment