对象动画师更新侦听器继续像疯了一样射击

时间:2016-08-29 20:27:21

标签: android listener objectanimator

美好的一天.Android对象动画师像疯了一样继续射击没有任何帮助来阻止它!没有!请帮帮我,我做错了什么?

    AnimatedColorSpan span = new AnimatedColorSpan(context);
    final SpannableString spannableString = new SpannableString(textToShow);
    this.spannableString = spannableString;
    String substring = textToShow.toLowerCase();
    int start = textToShow.toLowerCase().indexOf(substring);
    int end = start + substring.length();
    spannableString.setSpan(span, start, end, 0);

    objectAnimator = ObjectAnimator.ofFloat(
            span, ANIMATED_COLOR_SPAN_FLOAT_PROPERTY, 0, 100);
    objectAnimator.setEvaluator(new FloatEvaluator());
    objectAnimator.addUpdateListener(updateListener);
    objectAnimator.setInterpolator(new LinearInterpolator());
    objectAnimator.setDuration(DURATION);
    objectAnimator.setRepeatCount(ValueAnimator.INFINITE);
    objectAnimator.start();

 private static final Property<AnimatedColorSpan, Float> ANIMATED_COLOR_SPAN_FLOAT_PROPERTY
        = new Property<AnimatedColorSpan, Float>(Float.class, "ANIMATED_COLOR_SPAN_FLOAT_PROPERTY") {
    @Override
    public void set(AnimatedColorSpan span, Float value) {
        span.setTranslateXPercentage(value);
    }

    @Override
    public Float get(AnimatedColorSpan span) {
        return span.getTranslateXPercentage();
    }
};

public static RainbowAnimation get() {
    return rainbowAnimation;
}

public void stopRainbowAnimation() {
    stopCalled = true;
    if (objectAnimator != null) {
        objectAnimator.removeUpdateListener(updateListener);
        objectAnimator.cancel();
        objectAnimator.removeAllListeners();
        objectAnimator.removeAllUpdateListeners();
        textViewToAttach.setText(textToShow);
    }
    System.gc();
}


private ValueAnimator.AnimatorUpdateListener updateListener = new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator valueAnimator) {
        if (!stopCalled) {
            textViewToAttach.setText(spannableString);
        } else {
            if (objectAnimator != null) {
                objectAnimator.setDuration(10);
                objectAnimator.removeUpdateListener(this);
                objectAnimator = null;
            }
        }
    }
};

我已经在这里尝试了一切,你可以看到我正在删除所有可能删除的东西,但它只是记录而且它让我疯狂,因为堆积增长为地狱! 我的代码人员在这里做错了什么问题?

1 个答案:

答案 0 :(得分:2)

如果你想停止动画师电话

objectAnimator.end();

如果您希望动画不重复,请注释此行

objectAnimator.setRepeatCount(ValueAnimator.INFINITE);

它不会再次重复动画。