Skip to content
This repository has been archived by the owner on Feb 8, 2022. It is now read-only.

Problem with looping to define an animation #4

Open
RafaRuiz opened this issue Jan 20, 2016 · 1 comment
Open

Problem with looping to define an animation #4

RafaRuiz opened this issue Jan 20, 2016 · 1 comment

Comments

@RafaRuiz
Copy link

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.

@liyujiang-gzu
Copy link
Contributor

I seem also encountered the same problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants