0

I am using nineoldandroid for Animation.

My codes as follow:

Button mTarget;
Animator mTargetAnim;
AnimatorSet mTargetScaleAnimSet;

private void createAnimation() {
    if (mTargetAnim == null) {
        ObjectAnimator yAnim = ObjectAnimator.ofFloat(mTarget, "y",
                mTarget.getY(), mTarget.getY() + 500).setDuration(3500);
        yAnim.setRepeatCount(0);
        yAnim.setRepeatMode(ValueAnimator.REVERSE);
        yAnim.setInterpolator(new AccelerateInterpolator(2f));
        yAnim.addListener(this);

        ObjectAnimator xAnim = ObjectAnimator.ofFloat(mTarget, "x",
                mTarget.getX(), mTarget.getX() + 500).setDuration(3500);
        xAnim.setStartDelay(0);
        xAnim.setRepeatCount(0);
        xAnim.setRepeatMode(ValueAnimator.REVERSE);
        xAnim.setInterpolator(new AccelerateInterpolator(2f));
        // the first AnimatorSet
        AnimatorSet xyAnimSet = new AnimatorSet();
        xyAnimSet.playTogether(yAnim, xAnim);

        mTargetScaleAnimSet = new AnimatorSet();
        ObjectAnimator scaleXAnim = ObjectAnimator.ofFloat(mTarget,
                "scaleX", 1f, 0f, 0.2f, 0f);
        ObjectAnimator scaleYAnim = ObjectAnimator.ofFloat(mTarget,
                "scaleY", 1f, 0f, 0.2f, 0f);
        mTargetScaleAnimSet.playTogether(scaleXAnim,
                scaleYAnim);
        mTargetScaleAnimSet.setDuration(3000);
        mTargetScaleAnimSet.addListener(this);


        mTargetAnim = new AnimatorSet();
        ((AnimatorSet) mTargetAnim).playSequentially(xyAnimSet, mTargetScaleAnimSet);

        mTargetAnim.addListener(this);
    }
}

Before the beginning of the second Animator(mTargetScaleAnimSet), I call the end() method to end the entire AnimatorSet. However, I found the end() method can not end all of child Animators in the AnimatorSet.

Q: How to all of child Animators playing Sequentially?
see2851
  • 627
  • 1
  • 9
  • 13

1 Answers1

0

After some brainstorming, I found a solution as follow:

Firstly:

mScaleAnimSet.setStartDelay(3500);

Then:

mTargetAnimSet.playSequentially(mTransAnimSet, mScaleAnimSet);

change to:

mTargetAnimSet.playTogether(mTransAnimSet, mScaleAnimSet );

I think the key is that if the Animation does not start, you can not end it.

see2851
  • 627
  • 1
  • 9
  • 13