Android animation does not repeat

后端 未结 23 1490
囚心锁ツ
囚心锁ツ 2020-11-27 14:01

I\'m trying to make simple animation that would repeat several times (or infinitely).
It seems that android:repeatCount does not work!
Here is my anim

23条回答
  •  情话喂你
    2020-11-27 14:10

    After researching through the answers from internet, I found a solutions which works perfectly for me. (And yes, the repeatCount and repeatMode is extremely buggy when used together with animationSet).

    anim_rotate_fade.xml:

    
    
    
        
    
        
    
        
    
    
    

    In activity: (Solve it by introducing a slight delay after animation ended).

    ImageView starlightImageView = new ImageView(this);
    starlightImageView.setImageResource(R.drawable.starlight);
    final AnimatorSet animate = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.anim.anim_rotate_fade);
    AnimatorListenerAdapter animatorListener = new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            new Handler().postDelayed(new Runnable() {
                @Override public void run() {
                    animate.start();
                }
            }, 1000);
        }
    };
    animate.setTarget(starlightImageView);
    animate.addListener(animatorListener);
    

    There are a lot of classes you would like to research on, but currently I'm using objectAnimator which is highly flexible. I wouldn't recommend to use Animation or AnimationUtils:

    • Animation
    • AnimationUtils
    • Animator
    • AnimatorInflater
    • AnimatorListener
    • AnimatorListenerAdapter

提交回复
热议问题