Android-ObjectAnimator无法在电池/省电模式下工作

时间:2018-08-24 12:30:10

标签: android android-animation objectanimator

在Android中,在节电模式下,ObjectAnimator将持续时间替换为0(零)。另外,在Android P Beta中,即使关闭了省电模式,这也是默认行为。这种线性动画有替代品吗?我想完全像Instagram,Facebook和WhatsApp一样实现故事进度条。预先感谢。

ObjectAnimator animator = ObjectAnimator.ofInt(scrollProgressBar, "progress", 100);
animator.setInterpolator(new LinearInterpolator());
animator.setDuration(duration);
animator.addListener(new AnimatorListenerAdapter() {
     @Override
     public void onAnimationEnd(Animator animation) {
          super.onAnimationEnd(animation);

          // Logic
          recyclerView.smoothScrollToPosition(mPosition + 1);
     }
});
animator.start();

我也尝试过在UI线程中运行,但是它不起作用

new Handler().post(new Runnable() {
     @Override
     public void run() {
          ObjectAnimator animator = ObjectAnimator.ofInt(scrollProgressBar, "progress", 100);
          animator.setInterpolator(new LinearInterpolator());
          animator.setDuration(duration);
          animator.addListener(new AnimatorListenerAdapter() {
               @Override
               public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);

                    // Logic
                    recyclerView.smoothScrollToPosition(mPosition + 1);
               }
          });
          animator.start();
     }
});

0 个答案:

没有答案