gpt4 book ai didi

java - ValueAnimator 只重复一次

转载 作者:太空狗 更新时间:2023-10-29 22:55:19 27 4
gpt4 key购买 nike

我正在尝试让 ValueAnimator 在结束后重复。我将它与 ListView 中的 SeekBar 一起使用。由于某种原因,ValueAnimator 将完成,再次触发 onAnimationEnd(),但是当它到达终点时 onAnimationEnd() 是再也没有打过电话。

    @Override
public View getContentView(int position, View convertView, ViewGroup parent) {
...
setupTimerBar(t);
...
}


private AnimatorListenerAdapter generateNewAnimatorListenerAdapter(final TylersContainer t) {
return new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
setupTimerBar(t);
}
};
}

private void setupTimerBar(TylersContainer t)
{
View view = t.getView();
BusTime arrivalTime = t.getBusTime();
int minutes = BusTime.differenceInMiuntes(arrivalTime, BusTime.now());
long milliseconds = minutes * 60 * 1000;

final TimerBar seekBar = (TimerBar) view.findViewById(R.id.SeekBar);

int progress = Utility.setProgress(arrivalTime, seekBar.getMax());
long duration = Utility.setAnimationDuration(progress);

seekBar.setProgress(progress);
seekBar.setAnimationDuration(duration);
seekBar.setAnimationStartDelay(milliseconds);
seekBar.setAnimatorListenerAdapter(generateNewAnimatorListenerAdapter(t));
}

seekBar 对象实际上是一个自定义对象,它包含一个SeekBar 和一个ValueAnimator,以下是相关位:

    //Constructor
public TimerBar(Context context) {
super(context);

startTime = Calendar.getInstance();
valueAnimator = ValueAnimator.ofInt(0, getMax());

//Override the update to set this object progress to the animation's value
valueAnimator.addUpdateListener(new AnimatorUpdateListener() {

@Override
public void onAnimationUpdate(ValueAnimator animation) {
int animProgress = (Integer) animation.getAnimatedValue();
setProgress(animProgress);

}
});
}

//Specify the start time by passing a long, representing the delay in milliseconds
public void setAnimationStartDelay(long milliseconds){

//Set the delay (if need be) and start the counter
if(milliseconds > 0)
valueAnimator.setStartDelay(milliseconds);

valueAnimator.setIntValues(this.getProgress(), this.getMax());

valueAnimator.start();
}


//Set the duration of the animation
public void setAnimationDuration(long duration){
valueAnimator.setDuration(duration);
}


public void setAnimatorListenerAdapter(AnimatorListenerAdapter ala){
valueAnimator.addListener(ala);
}

我不明白为什么它没有重复超过两次。

我已经尝试使用 Repeat 属性并将其设置为 INIFINITI 但这也没有帮助。


编辑:明确地说,我想要得到的是一个无限重复的动画,每次都有不同的持续时间。

最佳答案

我犯了错误,将 RepeatMode 设置为 infinite,但没有用,必须将其设置为 RepeatCount:

valueAnimator.setRepeatCount(ValueAnimator.INFINITE);

关于java - ValueAnimator 只重复一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20648788/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com