Как смешать ValueAnimator и RotateAnimation - PullRequest
0 голосов
/ 29 апреля 2019

Я пытаюсь смешать ValueAnimator и RotateAnimation. Я хочу, чтобы мой вид перемещался прямолинейно из одной позиции в другую, когда он вращается вокруг своего центра. Обе анимации работают отлично, когда я тестирую их в одиночку. Но когда я пытаюсь смешать их, это сходит с ума.

ЭТО МОЙ КОД

rotateAnimation = new RotateAnimation(0.0f, 360.0f,
                Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF, Animation.RELATIVE_TO_SELF,
                 Animation.RELATIVE_TO_SELF);
        rotateAnimation.setRepeatCount(-1);
        rotateAnimation.setDuration(1000);

public void makeAnimationFinal(final View view){

        ValueAnimator valueAnimator = ValueAnimator.ofFloat(animationMovementList.get(animationCounter).offSet, animationMovementList.get(animationCounter).moveTo);
        valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator()); // increase the speed first and then decrease
        valueAnimator.setDuration(animationMovementList.get(animationCounter).duration);
        view.setAnimation(rotateAnimation);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float progress = (float) animation.getAnimatedValue();
                if(isXDirection)
                view.setTranslationX(progress);

                else
                    view.setTranslationY(progress);

                if(progress == animationMovementList.get(animationCounter).moveTo){
                    animationCounter++;
                    if(animationCounter >= 4) {
                        animationCounter = 0;
//                        isXDirection = !isXDirection;
                    }

                    isXDirection = !isXDirection;
                    makeAnimationFinal(view);

                }

            }
        });

        valueAnimator.start();
    }
...