Home > other >  How can I implement another action after the animation has ended? - Java
How can I implement another action after the animation has ended? - Java

Time:03-17

Can anyone help? ===================================================== I tried like this:

Animation zoom, zoom_out;


zoomAnimation();
private void zoomAnimation() {
        zoom= AnimationUtils.loadAnimation(this,R.anim.fast_zoomin);
        avatar.startAnimation(zoom);
 
        //question
        if (zoom.hasEnded()){
            zoomoutAnimation();
        }
        //question

    }

    private void zoomoutAnimation() {
        zoom_out= AnimationUtils.loadAnimation(this,R.anim.fast_zoomout);
        avatar.startAnimation(zoom_out);
    }

CodePudding user response:

I'm not sure I understand the question correctly. But I think that you need just to add a module. When the animation ends, the object still exist, so you can connect an action with an intent-filter. Hope to be of help

CodePudding user response:

I made it so that when the animation started, exactly as many seconds elapsed as the animation lasted, after that another action will begin (C help of the Handler method).

private void zoomAnimation() {
        zoom = AnimationUtils.loadAnimation(this,R.anim.fast_zoomin);
        zoom_out = AnimationUtils.loadAnimation(this,R.anim.fast_zoomout);
        avatar.startAnimation(zoom);

        if (!zoom.hasStarted()){
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                public void run() {
                    avatar.startAnimation(zoom_out);
                }
            }, 1500); //seconds after which another action will start when
                      //condition that the first one started
        }

    }
  • Related