ViewAnimator icon indicating copy to clipboard operation
ViewAnimator copied to clipboard

Problem with looping to define an animation

Open RafaRuiz opened this issue 10 years ago • 1 comments

Hello.

I would like to make a loop and modify the ViewAnimator on the go.

So, theorically making this:

    ViewAnimator viewAnimator = ViewAnimator.animate(heart_progress).translationY(0, heart_progress.getHeight() / maxSeconds).descelerate().duration(1000);
    for (int i = 1; i < maxSeconds; i++) {

        final int finalI = i;
        viewAnimator.thenAnimate(heart_progress).translationY((i % maxSeconds) * heart_progress.getHeight() / maxSeconds, ((i + 1) % maxSeconds) * heart_progress.getHeight() / maxSeconds).descelerate().onStart(new AnimationListener.Start() {
            @Override
            public void onStart() {
                System.out.println("animation #"+ finalI);
            }
        }).duration(1000);
    }

    viewAnimator.start();

would be the same than doing this:

    ViewAnimator viewAnimator = ViewAnimator.animate(heart_progress).translationY(0, heart_progress.getHeight() / maxSeconds).descelerate().duration(1000).
    thenAnimate(heart_progress).translationY((1 % maxSeconds) * heart_progress.getHeight() / maxSeconds, ((1 + 1) % maxSeconds) * heart_progress.getHeight() / maxSeconds).descelerate().onStart(new AnimationListener.Start() {
        @Override
        public void onStart() {
            System.out.println("animation #"+ 1);
        }
    }).duration(900).
            thenAnimate(heart_progress).translationY((2 % maxSeconds) * heart_progress.getHeight() / maxSeconds, ((2 + 1) % maxSeconds) * heart_progress.getHeight() / maxSeconds).descelerate().onStart(new AnimationListener.Start() {
        @Override
        public void onStart() {
            System.out.println("animation #"+ 2);
        }
    }).duration(900).
            thenAnimate(heart_progress).translationY((3 % maxSeconds) * heart_progress.getHeight() / maxSeconds, ((3 + 1) % maxSeconds) * heart_progress.getHeight() / maxSeconds).descelerate().onStart(new AnimationListener.Start() {
        @Override
        public void onStart() {
            System.out.println("animation #"+ 3);
        }
    }).duration(900).
            thenAnimate(heart_progress).translationY((4 % maxSeconds) * heart_progress.getHeight() / maxSeconds, ((4 + 1) % maxSeconds) * heart_progress.getHeight() / maxSeconds).descelerate().onStart(new AnimationListener.Start() {
        @Override
        public void onStart() {
            System.out.println("animation #"+ 4);
        }
    }).duration(900).
            thenAnimate(heart_progress).translationY((5 % maxSeconds) * heart_progress.getHeight() / maxSeconds, ((5 + 1) % maxSeconds) * heart_progress.getHeight() / maxSeconds).descelerate().onStart(new AnimationListener.Start() {
        @Override
        public void onStart() {
            System.out.println("animation #"+ 5);
        }
    }).duration(900).
            thenAnimate(heart_progress).translationY((6 % maxSeconds) * heart_progress.getHeight() / maxSeconds, ((6 + 1) % maxSeconds) * heart_progress.getHeight() / maxSeconds).descelerate().onStart(new AnimationListener.Start() {
        @Override
        public void onStart() {
            System.out.println("animation #"+ 6);
        }
    }).duration(900).start();

but the result is pretty different:

CORRECT heart_correct

(please allow some time to load the GIF and an offset to start the video :D)

WRONG heart_wrong

(please allow some time to load the GIF and an offset to start the video :D)

What's wrong with the for loop?

Thanks.

RafaRuiz avatar Jan 20 '16 17:01 RafaRuiz

I seem also encountered the same problem.

liyujiang-gzu avatar Jan 29 '16 02:01 liyujiang-gzu