无法滚动背景工作的麻烦

时间:2017-04-17 13:58:48

标签: android animation

我试图让我的程序的背景图像自己无限滚动,但我使用的代码并不是将图像移动一点

    final ImageView backgroundOne = (ImageView) findViewById(R.id.background_one);
    final ImageView backgroundTwo = (ImageView) findViewById(R.id.background_two);

    final ValueAnimator animator = ValueAnimator.ofFloat(0.0f, 1.0f);
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.setInterpolator(new LinearInterpolator());
    animator.setDuration(10000L);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            final float progress = (float) animation.getAnimatedValue();
            final float width = backgroundOne.getWidth();
            final float translationX = width * progress;
            backgroundOne.setTranslationX(translationX);
            backgroundTwo.setTranslationX(translationX + width);
        }
    });
    animator.start();

0 个答案:

没有答案