1

当我单击开始按钮,然后结束按钮并再次单击开始按钮时,会导致以下异常:

10-08 08:57:57.963: E/AndroidRuntime(2009): java.lang.IllegalStateException: Circular dependencies cannot exist in AnimatorSet
10-08 08:57:57.963: E/AndroidRuntime(2009):     at android.animation.AnimatorSet.sortNodes(AnimatorSet.java:848)
10-08 08:57:57.963: E/AndroidRuntime(2009):     at android.animation.AnimatorSet.start(AnimatorSet.java:486)
10-08 08:57:57.963: E/AndroidRuntime(2009):     at com.example.propertyanimation.IndividualPropertyAnimationActivity$1.onClick(IndividualPropertyAnimationActivity.java:51)
10-08 08:57:57.963: E/AndroidRuntime(2009):     at android.view.View.performClick(View.java:4240)

源代码:

    pvhX = PropertyValuesHolder.ofFloat(View.SCALE_X, 2);
    pvhY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 2);
    scaleAnimation = ObjectAnimator.ofPropertyValuesHolder(mSubject, pvhX, pvhY);
    scaleAnimation.setRepeatCount(0);
    scaleAnimation.setRepeatMode(ValueAnimator.REVERSE);
    scaleAnimation.setDuration(3000);

    rotateAnimation = ObjectAnimator.ofFloat(mSubject, View.ROTATION, 360);
    rotateAnimation.setRepeatCount(ValueAnimator.INFINITE);
    rotateAnimation.setDuration(2000);

    mButtonStart.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setAniation.play(scaleAnimation).before(rotateAnimation);
            setAniation.start();
        }
    });
    mButtonEnd.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            setAniation.end();
        }
    });
4

2 回答 2

8

不要重复使用AnimatorSet,创建一个新的就可以了。构建器正在累积值并因此创建一个循环(动画取决于“之前”中的自身)

于 2013-12-17T19:46:37.577 回答
0

对我来说问题是因为我错误地重复了相同的动画两次

  final AnimatorSet set = new AnimatorSet();
    set.setDuration(250);
    set.setInterpolator(new AnticipateOvershootInterpolator());
    set.playTogether(galleryScaleX, galleryScaleY
            , cameraScaleX, cameraScaleY
            , audioScaleX, audioScaleY
            , documentScaleX, documentScaleY
            , locationScaleX, locationScaleY
            ,audioScaleX,audioScaleY/* same animation here*/
            , contactScaleX, contactScaleY);
    set.start();

只要确保你重复相同的动画

于 2018-03-05T13:42:59.500 回答