Android animation does not repeat

后端 未结 23 1464
囚心锁ツ
囚心锁ツ 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:12

    I tried to use Daniel's code to show animation exact number of times and had a problem: animation was shown approximatily n / 2 times, when n times expected.

    So I have modified Daniel's code:

    //...
    @Override
    public void onAnimationEnd(Animation arg0) {
        mCurrentCount++;
        if (mCurrentCount < REPEAT_COUNT) {  
            Animation anim = AnimationUtils.loadAnimation(BuzzFinderActivity.this, R.anim.crosshair_focusing);
            anim.setAnimationListener(this);
            brackets.post(new Runnable() {
                @Override
                public void run() {
                    brackets.startAnimation(anim);
                }
            }  
        } 
    }
    //... 
    

    Using variant, shown above, animation is shown exectly REPEAT_COUNT times, because View.post() method gives an ability to start new animation after finishing all actions, related with previous animation.

提交回复
热议问题