Problem with running multiple animations in AnimationSet

I am trying to implement an AnimationSet that contains several animations (Translate, Rotate and Alpha) several times. After the animation finishes and reaches a certain point, it will start again with various animation parameters. I completed this using the parameter setStartOffset;to time in the animation. However, I had a problem. Animation does not start from its original location (r1, alpha1 and trans1) and starts elsewhere. Any way to specify which animation will start?

        ////////////////////////////111111//////////////////////
    RotateAnimation r1 = new RotateAnimation(0,7,
            Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
    r1.setDuration(mAnimationDuration);
    r1.setFillAfter(true);
    r1.setInterpolator(interpolator);

    AlphaAnimation alpha1 = new AlphaAnimation((float) 0.7, (float) 0.7);
    alpha1.setDuration(mAnimationDuration);
    alpha1.setFillAfter(true);
    alpha1.setInterpolator(interpolator);

    TranslateAnimation trans1 = new TranslateAnimation(0, -290, 0, 0);
    trans1.setDuration(mAnimationDuration);
    trans1.setFillAfter(true);
    trans1.setInterpolator(interpolator);

    /////////////////////222222222222/////////////////////////
    RotateAnimation r2 = new RotateAnimation(7, -7,
            Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
    r2.setDuration(mAnimationDuration);
    r2.setFillAfter(true);
    r2.setInterpolator(interpolator);
    r2.setStartOffset(mAnimationDuration);

    AlphaAnimation alpha2 = new AlphaAnimation((float) 0.7, 1);
    alpha2.setDuration(mAnimationDuration);
    alpha2.setFillAfter(true);
    alpha2.setInterpolator(interpolator);
    alpha2.setStartOffset(mAnimationDuration);

    TranslateAnimation trans2 = new TranslateAnimation(-290, -580, 0, 0);
    trans2.setDuration(mAnimationDuration);
    trans2.setFillAfter(true);
    trans2.setInterpolator(interpolator);
    trans2.setStartOffset(mAnimationDuration);

    //////////////3333333///////////////////////////////
    RotateAnimation r3 = new RotateAnimation(-7, -7,
            Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
    r3.setDuration(mAnimationDuration);
    r3.setFillAfter(true);
    r3.setInterpolator(interpolator);
    r3.setStartOffset(mAnimationDuration*2);

    AlphaAnimation alpha3 = new AlphaAnimation((float) 0.7, 1);
    alpha3.setDuration(mAnimationDuration);
    alpha3.setFillAfter(true);
    alpha3.setInterpolator(interpolator);
    alpha3.setStartOffset(mAnimationDuration*2);

    TranslateAnimation trans3 = new TranslateAnimation(-580, -580, 0, 0);
    trans3.setDuration(mAnimationDuration);
    trans3.setFillAfter(true);
    trans3.setInterpolator(interpolator);
    trans3.setStartOffset(mAnimationDuration*2);

    /////////////4/44444//////////////////////
    RotateAnimation r4 = new RotateAnimation(-7, 7,
            Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
    r4.setDuration(mAnimationDuration);
    r4.setFillAfter(true);
    r4.setInterpolator(interpolator);
    r4.setStartOffset(mAnimationDuration*3);

    AlphaAnimation alpha4 = new AlphaAnimation(1, 1);
    alpha4.setDuration(mAnimationDuration);
    alpha4.setFillAfter(true);
    alpha4.setInterpolator(interpolator);
    alpha4.setStartOffset(mAnimationDuration*3);

    TranslateAnimation trans4 = new TranslateAnimation(-580, -870, 0, 0);
    trans4.setDuration(mAnimationDuration);
    trans4.setFillAfter(true);
    trans4.setInterpolator(interpolator);
    trans4.setStartOffset(mAnimationDuration*3);
    //////////////555555555555////////////////////////////
    RotateAnimation r5 = new RotateAnimation(7, -7,
            Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0);
    r5.setDuration(mAnimationDuration);
    r5.setFillAfter(true);
    r5.setInterpolator(interpolator);
    r5.setStartOffset(mAnimationDuration*4);

    AlphaAnimation alpha5 = new AlphaAnimation(1, 1);
    alpha5.setDuration(mAnimationDuration);
    alpha5.setFillAfter(true);
    alpha5.setInterpolator(interpolator);
    alpha5.setStartOffset(mAnimationDuration*4);

    TranslateAnimation trans5 = new TranslateAnimation(-870, -1160, 0, 0);
    trans5.setDuration(mAnimationDuration);
    trans5.setFillAfter(true);
    trans5.setInterpolator(interpolator);
    trans5.setStartOffset(mAnimationDuration*4);

firstAnimationView1 = new AnimationSet(true);
    firstAnimationView1.addAnimation(r1);
    firstAnimationView1.addAnimation(r2);
    firstAnimationView1.addAnimation(r3);
    firstAnimationView1.addAnimation(alpha1);
    firstAnimationView1.addAnimation(alpha2);
    firstAnimationView1.addAnimation(alpha3);
    firstAnimationView1.addAnimation(trans1);
    firstAnimationView1.addAnimation(trans2);
    firstAnimationView1.addAnimation(trans3);
+3
source share

All Articles