Android进度条动画

时间:2016-02-27 21:20:41

标签: android animation progress-bar android-animation android-progressbar

我正在尝试创建一个从LEFT到RIGHT然后从LEFT到RIGHT完全清空的进度条。它只有一次动画效果很好。然后从右边填充到左边,并向右清空。

应该是什么: http://i.imgur.com/ZuAsngc.gif?1

现在正在做什么: http://i.imgur.com/69qixqO.gifv

我们可以在gif中看到它第一次做得很好。然后它搞砸了。我不知道它是否与 interpolatedTime

有关
ProgressBarAnimation anim = new ProgressBarAnimation(progressBar, 0,100);
        anim.setDuration(1000);
        anim.setRepeatCount(Animation.INFINITE);
        progressBar.startAnimation(anim);

进步等级

class ProgressBarAnimation extends Animation{
    private ProgressBar progressBar;
    private float from;
    private float  to;
    private boolean isForward;
    private float value;

    public ProgressBarAnimation(ProgressBar progressBar, float from, float to) {
        super();
        this.progressBar = progressBar;
        this.from = from;
        this.to = to;
        isForward = true;
    }

    @Override
    protected void applyTransformation(float interpolatedTime, Transformation t) {
        super.applyTransformation(interpolatedTime, t);
        if(isForward) {
            value = from + (to - from) * interpolatedTime;
            progressBar.setProgress((int) value);
            if(value == 100){
                isForward = false;
                progressBar.setRotation(180);
                value = 0;
            }
        }
        else{
            value = to + (from - to) * interpolatedTime;
            progressBar.setProgress((int) value);
            if(value2 == 0){
                isForward = true;
                progressBar.setRotation(180);
                value = 100;
            }
        }
    }
}

0 个答案:

没有答案