Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

android - Set animation listener to Activity animations

I am using overridePendingTransition method to perform custom Activity animations.

I would like to know when the animation ends ( a callback/listener ).

Is there any direct way of achieving this, if not please suggest me some work around.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I use this method to start any animation (resID of the animation XML). If nextPuzzleOnEnd is true, the method "nextPuzzle" is called when the animation has finished.

The method is part of my puzzle-apps and I use it to display any success animation and afterwards (after anim has finished) continue with the next puzzle.

 /*
 * start animation (any view)
 */
 private void startAnimation(View v, int resId, Boolean nextPuzzleOnEnd){
    Animation anim;

    if(v!=null){    // can be null, after change of orientation
            anim = AnimationUtils.loadAnimation(this.getContext(),resId);
            anim.setFillAfter(false);
            v.setAnimation(anim);
            if( nextPuzzleOnEnd ){
                anim.setAnimationListener(new AnimationListener() {
                    public void onAnimationStart(Animation anim)
                    {
                    };
                    public void onAnimationRepeat(Animation anim)
                    {
                    };
                    public void onAnimationEnd(Animation anim)
                    {
                        nextPuzzle();
                    };
                });                     
            }
            v.startAnimation(anim);                 
    }
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...