在第二次启动ObjectAnimator之前删除默认延迟

时间:2016-05-06 13:25:59

标签: android android-animation horizontalscrollview objectanimator

我使用HorizontalScrollView(左 - >右 - >左)滚动ObjectAnimator。因此,结果应该是从一侧到另一侧的无限滚动。

问题是我开始制作右边动画后的1秒延迟 - >剩下。是什么导致这种行为?

我已经创建了2个动画并且一个接一个地开始(如果你知道更好的解决方案,那就是):

final ObjectAnimator animRight = ObjectAnimator.ofInt(hScrollView, "scrollX", hScrollView.getRight());
animRight.setDuration(SCROLL_DURATION);

final ObjectAnimator animLeft = ObjectAnimator.ofInt(hScrollView, "scrollX", 0);
animLeft.setDuration(SCROLL_DURATION);

animRight.addListener(new Animator.AnimatorListener() {
    @Override
    public void onAnimationStart(Animator animation) {}

    @Override
    public void onAnimationEnd(Animator animation) {
        animLeft.start();
    }

    @Override
    public void onAnimationCancel(Animator animation) {}

    @Override
     public void onAnimationRepeat(Animator animation) {}
 });

 animLeft.addListener(new Animator.AnimatorListener() {
     @Override
     public void onAnimationStart(Animator animation) {}

     @Override
     public void onAnimationEnd(Animator animation) {
         animRight.start(); //delay occurs here
     }

     @Override
     public void onAnimationCancel(Animator animation) {}

     @Override
     public void onAnimationRepeat(Animator animation) {}
 });

 animRight.start();

1 个答案:

答案 0 :(得分:1)

您是否尝试过对您的动画应用线性插值器?

默认插值器不是线性的,因此可能导致延迟。申请:

animRight.setInterpolator(new LinearInterpolator());
animLeft.setInterpolator(new LinearInterpolator());