Android animation does not repeat

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

    To get a repeating animation I utilized the animation listener, and called the animation again when it ended. This does a camera reticule focusing like animation with brackets.

    Here is the animation layout xml

    
    
    
    
    
    
    

    Here is the java code

     public void startAnimation() {
    
                View brackets = findViewById(R.id.brackets);
                brackets.setVisibility(View.VISIBLE);
    
                Animation anim = AnimationUtils.loadAnimation(BuzzFinderActivity.this, R.anim.crosshair_focusing);
                anim.setAnimationListener(new AnimationListener() {
    
                    @Override
                    public void onAnimationEnd(Animation arg0) {
                        Animation anim = AnimationUtils.loadAnimation(BuzzFinderActivity.this, R.anim.crosshair_focusing);
                        anim.setAnimationListener(this);
                        brackets.startAnimation(anim);
    
                    }
    
                    @Override
                    public void onAnimationRepeat(Animation arg0) {
                        // TODO Auto-generated method stub
    
                    }
    
                    @Override
                    public void onAnimationStart(Animation arg0) {
                        // TODO Auto-generated method stub
    
                    }
    
                });
    
    
                brackets.startAnimation(anim);
    }
    

提交回复
热议问题