简体   繁体   中英

Wait for rotation animation to finish in android before opening new activity?

My code is as follows:

connectButton.setOnClickListener(new View.OnClickListener(){
        public void onClick(View view){
            pointer.animate().rotation(connectButtonAngle - 45).start();
            Intent intent = new Intent(MainScreenActivity.this, NextActivity.class);
            startActivity(intent);
        }
    });

How would I get it to wait for the pointer to finish spinning before starting the next activity?

Change your implementation to this, and you will get when Animation ends.

connectButton.setOnClickListener(new View.OnClickListener(){
        public void onClick(View view){
       pointer.animate().rotation(connectButtonAngle - 45).setListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
              Intent intent = new Intent(MainScreenActivity.this, NextActivity.class);
              startActivity(intent);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        }).start();


        }
    });

Try this code:

pointer.animate()
    .rotation(connectButtonAngle - 45)
    .withEndAction(new Runnable() {
      @Override
      public void run() {
          Intent intent = new Intent(MainScreenActivity.this, NextActivity.class);
          startActivity(intent);
      }
    })
    .start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM