ValueAnimator只重复一次

 销魂成浩龙_346 发布于 2023-02-09 15:45

我试图在ValueAnimator它结束后重复一遍.我使用它与一个SeekBarListView.由于某种原因,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对象实际上是一个自定义对象,其中包含a SeekBar和a 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但是这也没有帮助.


编辑:要清楚,我想要得到的是一个无限期重复的动画,每次都有不同的持续时间.

1 个回答
  • 我已经将设置RepeatMode为无限的错误设置为无效,这必须设置为RepeatCount:

    valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
    

    2023-02-09 15:49 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有