我想創建一個不斷變化的背景動畫,並在我的視圖中持續運行,並且我已經能夠使用此代碼創建顏色更改動畫。使用軟動畫更改視圖背景色無限Android
int prevColor = getRandomColor();
ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), prevColor, getRandomColor(prevColor));
colorAnimation.setRepeatCount(ValueAnimator.INFINITE);
colorAnimation.setDuration(transitionTime); // milliseconds
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
backgroundBase.setBackgroundColor((int) animator.getAnimatedValue());
}
});
colorAnimation.start();
它順利運行,但是......
當動畫結束時,突然追溯到改變顏色來第一個沒有軟動畫像第一次
然後,我想要做的是當動畫完成時,我希望動畫從我的顏色列表中獲取新的隨機顏色,以便顏色不斷地不斷變化(不僅僅是來回反轉)
我找不到在
colorAnimation
setAnimationListener
,所以我不能使用覆蓋方法onAnimationEnd
我應該怎麼做才能做到這一點?
ValueAnimator中沒有setFillAfter方法。 我終於設法使用'addListener(new Animator.AnimatorListener(){... onAnimationRepeat(Animator animation(){...})})' – fadeltd