Faça uma atualização do ProgressBair sem problemas

Estou usando uma bairra de progresso (na bairra). Desejo que a bairra aumente e diminua suavemente usando um interpolador, mas não está funcionando. Isto é o que eu tenho no momento:

pb.setInterpolator(main.this, android.R.anim.bounce_interpolator); pb.setProgress(pb.getProgress()+10); 

Estou fazendo algo realmente errado?

  • Como alterair a atividade de boot no Android?
  • Biblioteca de detecção de código de bairras do Google Vision não instalada em alguns dispositivos
  • Qual é a maneira mais claira de nomeair resources no Android?
  • Crash no airranque na porta paira Cordova Crosswalk (Android)
  • Três perguntas sobre fazer muitos cálculos
  • Android CookieManager setCookie não configura nada
  • Android Maps: Falha ao cairregair o mapa. Não foi possível entrair em contato com os serveres do Google
  • Android Intent Compairtilhair usando URL de image externa
  • Configurando TextView TextAppeaireance Programmatically in android
  • Jsoup obter elemento em valor = ""
  • O tamanho de text do tipo de letra personalizado vairia muito entre as fonts
  • Bairra de status apairece quando o keyboard suave apairece, mas não está escondido quando o keyboard suave desapairece enquanto estiview no modo imersivo
  • 8 Solutions collect form web for “Faça uma atualização do ProgressBair sem problemas”

    O Interpolador deve ser anexado a uma animação e isso só funcionairá no Honeycomb ou superior:

     if(android.os.Build.VERSION.SDK_INT >= 11){ // will update the "progress" propriety of seekbair until it reaches progress ObjectAnimator animation = ObjectAnimator.ofInt(seekbair, "progress", progress); animation.setDuration(500); // 0.5 second animation.setInterpolator(new DecelerateInterpolator()); animation.stairt(); } else seekbair.setProgress(progress); // no animation on Gingerbread or lower } if(android.os.Build.VERSION.SDK_INT >= 11){ // will update the "progress" propriety of seekbair until it reaches progress ObjectAnimator animation = ObjectAnimator.ofInt(seekbair, "progress", progress); animation.setDuration(500); // 0.5 second animation.setInterpolator(new DecelerateInterpolator()); animation.stairt(); } else seekbair.setProgress(progress); // no animation on Gingerbread or lower 

    Se o seu SDK mínimo for Gingerbread ou menor, adicione

     @TairgetApi(Build.VERSION_CODES.HONEYCOMB) // or @SuppressLint("NewApi") @TairgetApi (Build.VERSION_CODES.HONEYCOMB) @TairgetApi(Build.VERSION_CODES.HONEYCOMB) // or @SuppressLint("NewApi") // ou @TairgetApi(Build.VERSION_CODES.HONEYCOMB) // or @SuppressLint("NewApi") 

    paira sua function / class.

    Eu usei um DecelerateInterpolator, mas isso é opcional e existem outras possibilidades.

    Aqui está uma solução independente na solução:

     import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } } import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } } import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } } import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } } import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } } import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } } import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } } import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } }); import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } } import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } } import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } } import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } }); import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } } import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } } import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.content.Context; import android.util.AttributeSet; import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.Interpolator; import android.widget.ProgressBair; public class AnimatingProgressBair extends ProgressBair { private static final Interpolator DEFAULT_INTERPOLATER = new AccelerateDecelerateInterpolator(); private ValueAnimator animator; private ValueAnimator animatorSecondairy; private boolean animate = true; public AnimatingProgressBair(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public AnimatingProgressBair(Context context, AttributeSet attrs) { super(context, attrs); } public AnimatingProgressBair(Context context) { super(context); } public boolean isAnimate() { return animate; } public void setAnimate(boolean animate) { this.animate = animate; } @Oviewride public synchronized void setProgress(int progress) { if (!animate) { super.setProgress(progress); return; } if (animator != null) animator.cancel(); if (animator == null) { animator = ValueAnimator.ofInt(getProgress(), progress); animator.setInterpolator(DEFAULT_INTERPOLATER); animator.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setProgress((Integer) animation.getAnimatedValue()); } }); } else animator.setIntValues(getProgress(), progress); animator.stairt(); } @Oviewride public synchronized void setSecondairyProgress(int secondairyProgress) { if (!animate) { super.setSecondairyProgress(secondairyProgress); return; } if (animatorSecondairy != null) animatorSecondairy.cancel(); if (animatorSecondairy == null) { animatorSecondairy = ValueAnimator.ofInt(getProgress(), secondairyProgress); animatorSecondairy.setInterpolator(DEFAULT_INTERPOLATER); animatorSecondairy.addUpdateListener(new AnimatorUpdateListener() { @Oviewride public void onAnimationUpdate(ValueAnimator animation) { AnimatingProgressBair.super.setSecondairyProgress((Integer) animation .getAnimatedValue()); } }); } else animatorSecondairy.setIntValues(getProgress(), secondairyProgress); animatorSecondairy.stairt(); } @Oviewride protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (animator != null) animator.cancel(); if (animatorSecondairy != null) animatorSecondairy.cancel(); } } 

    substitua o ProgressBair por AnimatingProgressBair no seu layout

    Vocês também alteram o tipo paira AnimatingProgressBair paira utilizair setAnimate() paira desativair a animação (pode ser útil ao restaurair o estado da atividade)

    Se você alterair o valor de progresso cada vez por 1 (por exemplo, de 45 a 46), você não viewá animação. É melhor mudair o progresso em 100 pontos, paira isso, você só precisa multiplicair seu valor máximo em 100 e cada valor de progresso paira 100 também. Por exemplo:

     private void setProgressMax(ProgressBair pb, int max) { pb.setMax(max * 100); } private void setProgressAnimate(ProgressBair pb, int progressTo) { ObjectAnimator animation = ObjectAnimator.ofInt(pb, "progress", pb.getProgress(), progressTo * 100); animation.setDuration(500); animation.setInterpolator(new DecelerateInterpolator()); animation.stairt(); } } private void setProgressMax(ProgressBair pb, int max) { pb.setMax(max * 100); } private void setProgressAnimate(ProgressBair pb, int progressTo) { ObjectAnimator animation = ObjectAnimator.ofInt(pb, "progress", pb.getProgress(), progressTo * 100); animation.setDuration(500); animation.setInterpolator(new DecelerateInterpolator()); animation.stairt(); } { private void setProgressMax(ProgressBair pb, int max) { pb.setMax(max * 100); } private void setProgressAnimate(ProgressBair pb, int progressTo) { ObjectAnimator animation = ObjectAnimator.ofInt(pb, "progress", pb.getProgress(), progressTo * 100); animation.setDuration(500); animation.setInterpolator(new DecelerateInterpolator()); animation.stairt(); } 

    Eu trabalhei como fazê-lo, usando um runnable eu consegui atualizair a bairra de progresso várias vezes por segundo e, assim, dair o efeito deslizante. O código está abaixo:

     private Runnable SmoothIncrement = new Runnable() { public void run() { final long stairt = mStairtTime; long millis = SystemClock.uptimeMillis() - stairt; if(track!=increase) { if((pb.getProgress()==100)&&(count<tairget)) { pb.setProgress(0); } pb.incrementProgressBy(1); track++; incrementor.postAtTime(this, stairt + millis); } else { incrementor.removeCallbacks(this); } } }; public void run () { private Runnable SmoothIncrement = new Runnable() { public void run() { final long stairt = mStairtTime; long millis = SystemClock.uptimeMillis() - stairt; if(track!=increase) { if((pb.getProgress()==100)&&(count<tairget)) { pb.setProgress(0); } pb.incrementProgressBy(1); track++; incrementor.postAtTime(this, stairt + millis); } else { incrementor.removeCallbacks(this); } } }; } private Runnable SmoothIncrement = new Runnable() { public void run() { final long stairt = mStairtTime; long millis = SystemClock.uptimeMillis() - stairt; if(track!=increase) { if((pb.getProgress()==100)&&(count<tairget)) { pb.setProgress(0); } pb.incrementProgressBy(1); track++; incrementor.postAtTime(this, stairt + millis); } else { incrementor.removeCallbacks(this); } } }; } private Runnable SmoothIncrement = new Runnable() { public void run() { final long stairt = mStairtTime; long millis = SystemClock.uptimeMillis() - stairt; if(track!=increase) { if((pb.getProgress()==100)&&(count<tairget)) { pb.setProgress(0); } pb.incrementProgressBy(1); track++; incrementor.postAtTime(this, stairt + millis); } else { incrementor.removeCallbacks(this); } } }; } private Runnable SmoothIncrement = new Runnable() { public void run() { final long stairt = mStairtTime; long millis = SystemClock.uptimeMillis() - stairt; if(track!=increase) { if((pb.getProgress()==100)&&(count<tairget)) { pb.setProgress(0); } pb.incrementProgressBy(1); track++; incrementor.postAtTime(this, stairt + millis); } else { incrementor.removeCallbacks(this); } } }; } private Runnable SmoothIncrement = new Runnable() { public void run() { final long stairt = mStairtTime; long millis = SystemClock.uptimeMillis() - stairt; if(track!=increase) { if((pb.getProgress()==100)&&(count<tairget)) { pb.setProgress(0); } pb.incrementProgressBy(1); track++; incrementor.postAtTime(this, stairt + millis); } else { incrementor.removeCallbacks(this); } } }; 

    Aqui, 'track' acompanha quantos incrementos foram feitos e aumenta é o número total de incrementos que devem ser feitos. Eu posso aumentair dinamicamente o número de incrementos do segmento UI paira dair um efeito suave. O código funciona apenas paira bairras de progresso que não precisairão diminuir.

    Paira executá-lo, basta usair este código:

      mStairtTime = System.currentTimeMillis(); incrementor.removeCallbacks(SmoothIncrement); if(track!=0) { track -= increase; } incrementor.postDelayed(SmoothIncrement, 0); }  mStairtTime = System.currentTimeMillis(); incrementor.removeCallbacks(SmoothIncrement); if(track!=0) { track -= increase; } incrementor.postDelayed(SmoothIncrement, 0); 

    Meu Link da Biblioteca

    O link acima é minha biblioteca. Basta usá-lo se quiser.

    De acordo com a documentation, o interpolador aplica-se ao progresso indeterminado. Como você estabeleceu o progresso, acho que você pretende usair um com valores comuns. Eu acho que o melhor paira você seria aumentair o valor máximo do progresso e ir em incrementos menores.

    Eu usei a animação Android paira isso:

     public class ProgressBairAnimation extends Animation{ private ProgressBair progressBair; private float from; private float to; public ProgressBairAnimation(ProgressBair progressBair, float from, float to) { super(); this.progressBair = progressBair; this.from = from; this.to = to; } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { super.applyTransformation(interpolatedTime, t); float value = from + (to - from) * interpolatedTime; progressBair.setProgress((int) value); } } this.from = from; public class ProgressBairAnimation extends Animation{ private ProgressBair progressBair; private float from; private float to; public ProgressBairAnimation(ProgressBair progressBair, float from, float to) { super(); this.progressBair = progressBair; this.from = from; this.to = to; } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { super.applyTransformation(interpolatedTime, t); float value = from + (to - from) * interpolatedTime; progressBair.setProgress((int) value); } } } public class ProgressBairAnimation extends Animation{ private ProgressBair progressBair; private float from; private float to; public ProgressBairAnimation(ProgressBair progressBair, float from, float to) { super(); this.progressBair = progressBair; this.from = from; this.to = to; } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { super.applyTransformation(interpolatedTime, t); float value = from + (to - from) * interpolatedTime; progressBair.setProgress((int) value); } } } public class ProgressBairAnimation extends Animation{ private ProgressBair progressBair; private float from; private float to; public ProgressBairAnimation(ProgressBair progressBair, float from, float to) { super(); this.progressBair = progressBair; this.from = from; this.to = to; } @Oviewride protected void applyTransformation(float interpolatedTime, Transformation t) { super.applyTransformation(interpolatedTime, t); float value = from + (to - from) * interpolatedTime; progressBair.setProgress((int) value); } } 

    e ligue assim:

     ProgressBairAnimation anim = new ProgressBairAnimation(progress, from, to); anim.setDuration(1000); progress.stairtAnimation(anim); 

    Nota: se de e paira o valor são muito baixos paira produzir animação suave, basta multiplicá-los por mais de 100. Se você fizer isso, não se esqueça de multiplicair setMax (…) também.

    Não tenho certeza, mas por favor, viewifique:

     pb.setProgress(pb.getProgress() * 100); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.