A
A
artshelom2018-11-10 14:15:33
Android
artshelom, 2018-11-10 14:15:33

How to return the view to its place after the animation?

I have a view in the animation moving. How to make them return to their original position after animation. I understand what should be written in onAnimationEnd, but what should I write there to make it work??

ValueAnimator positionAnimator = ValueAnimator.ofFloat(0, -150);
        positionAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float value = (float) animation.getAnimatedValue();
                cloverImage.setTranslationY(value);
                cloverBack.setTranslationY(value);
                cloverText.setTranslationY(value);
            }
        });
        ObjectAnimator rotationAnimator = ObjectAnimator.ofFloat(cloverImage, "rotation", 0, 480);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(positionAnimator).with(rotationAnimator);
        animatorSet.setDuration(1000);
        animatorSet.start();
        animatorSet.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Chvarkov, 2018-11-12
@artshelom

I don’t know the exact solution, but I would look at 2 options:
1) do the animation in the opposite direction
2) remember the view state before the animation and change the values ​​​​to the initial ones at the end of the animation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question