java – Issues creating an animation with only an initial start offset-ThrowExceptions

Exception or error:

I am trying to implement a “pairing” animation into my activity but am having trouble getting it to work properly. what I have are several ImageViews that move left to right and back again on an infinite repeat but are staggered out, I believe it is called a caterpiller animation.

I am using an XML Animation with a StartOffset. The problem is that is when the animation repeats, it also repeats the offset. I only want the offset to happen when the animation is first started and not on repeats.

I have tried using ObjectAnimators but they introduce several other problems that make them just not usable and feel like a bodge. I have also tried setting the offset to zero on animation end/repeat but still nothing.

I have been trying to figure this out for a week so some help would be greatly appreciated. Thanks.

Here is the code for my Object animator:

<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1250"
    android:valueTo="440"
    android:fillAfter="false"
    android:valueType="floatType"
    android:propertyName="translationX"
    android:repeatCount="infinite"
    android:startOffset="1100"
    android:repeatMode="reverse"/>

here is the code for my Animation:

<set xmlns:android="http://schemas.android.com/apk/res/android" 
     android:duration="1250" 
     android:fillAfter="false">
     <translate
         android:interpolator="@android:anim/linear_interpolator"
         android:repeatCount="infinite"
         android:repeatMode="reverse"
         android:toXDelta="92%p">
     </translate>
</set>

The XML of the ImageView I am trying to animate – there are several of these:

<ImageView
    android:layout_width="12dp"
    android:layout_height="12dp"
    android:id="@+id/pairing_circle_four"
    android:background="@drawable/small_green_circle"/>

The Java code for running the animations:

mCircleAnimation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.circle_animation);

mFirstStaggeredAnim = AnimatorInflater.loadAnimator(this, R.animator.staggered_animation_300);

mFirstStaggeredAnim.setTarget(mCircleTwo);

mSecondStaggeredAnim = AnimatorInflater.loadAnimator(this, R.animator.staggered_pairing_animation_600);
mSecondStaggeredAnim.setTarget(mCircleThree);

mThirdStaggeredAnim = AnimatorInflater.loadAnimator(this, R.animator.staggered_animation_1100);
mThirdStaggeredAnim.setTarget(mCircleFour);

mFourthStaggeredAnim = AnimatorInflater.loadAnimator(this, R.animator.staggered_animation_1400);
mFourthStaggeredAnim.setTarget(mCircleFive);

mFifthStaggeredAnim = AnimatorInflater.loadAnimator(this, R.animator.staggered_animation_1700);
mFifthStaggeredAnim.setTarget(mCircleSix);

mSixthStaggeredAnim = AnimatorInflater.loadAnimator(this, R.animator.staggered_animation_2000);
mSixthStaggeredAnim.setTarget(mCircleSeven);

fadeInFromBottom.setAnimationListener(new Animation.AnimationListener() {
    @Override
    public void onAnimationStart(Animation animation) {

    }

    @Override
    public void onAnimationEnd(Animation animation) {
        mCircleOne.startAnimation(mCircleAnimation);
        mFirstStaggeredAnim.start();
        mSecondStaggeredAnim.start();
        mThirdStaggeredAnim.start();
        mFourthStaggeredAnim.start();
        mFifthStaggeredAnim.start();
        mSixthStaggeredAnim.start();
    }

    @Override
    public void onAnimationRepeat(Animation animation) {

    }
});
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *