Smooth Progress Bar Animation

前端 未结 9 861
鱼传尺愫
鱼传尺愫 2021-01-01 10:34

I\'m trying to implement a smooth animation for my ProgressBar, but when I increase the time (30 seconds), the animation is no longer smooth.

Example wi

9条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-01 10:48

    You can make custom clas like this :

    public class CustomProgressBar extends ProgressBar {
    private static final long DEFAULT_DELAY = 500;
    private static final long DEFAULT_DURATION = 1000;
    
    public CustomProgressBar(Context context) {
        super(context);
    }
    
    public CustomProgressBar(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    public CustomProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    
    public synchronized void setProgress(float progress) {
        super.setProgress((int) progress);
    }
    
    @Override
    public synchronized void setProgress(int progress) {
        super.setProgress(progress);
    }
    
    public void startLcpProgressAnim(int progressTo) {
       startLcpProgressAnim(DEFAULT_DELAY, progressTo);
    }
    
    public void startLcpProgressAnim(long delay, int progressTo) {
       startLcpProgressAnim(DEFAULT_DURATION, delay, progressTo);
    }
    
    public void startLcpProgressAnim(long duration, long delay, float progressTo) {
        ObjectAnimator animation = ObjectAnimator.
                ofFloat(this, "progress",
                        (float)this.getProgress(), progressTo);
        animation.setDuration(duration);
        animation.setStartDelay(delay);
        animation.start();
    }
    }
    

提交回复
热议问题