Android, How can I know that the animation is finished?
Asked Answered
S

2

7

In my project i have a button. when user clicks on it, it shows and animation after that should load another activity.

@Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btnReadPage:
                startAnimation();
                //stopAnimation();
                //Toast.makeText(this, "Read Page Clicked", Toast.LENGTH_SHORT).show();
                //startActivity(new Intent(this, ReadPage.class));
                return;
        }

    }

according to above code(startActivity, commented), when I run the application and click on the button, animation will play. but if i uncomment it because of fast transition animation doesn't show. How can i inform that animation is finished? Thanks

Slobbery answered 6/10, 2011 at 2:39 Comment(2)
#4751439Pelagian
Check out the answer here. #2215235Grizelda
T
15

On your animation object call this code:

am1.setAnimationListener(new AnimationListener() {    
    @Override
    public void onAnimationStart(Animation animation) {  
        // TODO Auto-generated method stub
    }

    @Override
    public void onAnimationRepeat(Animation animation) {
        // TODO Auto-generated method stub
    }

    @Override
    public void onAnimationEnd(Animation animation) {
        // Pass the Intent to switch to other Activity

    }
});
Thirtytwo answered 26/3, 2012 at 13:0 Comment(0)
G
0

Update 2023 in Kotlin. Following Rahulkapil answer.

val animation = AnimationUtils.loadAnimation(requireContext(), R.anim.fade_in)

animation.fillAfter = true
animation.duration = 2000

animation.setAnimationListener(object : AnimationListener {
    override fun onAnimationStart(animation: Animation) {
        Log.d("////", "onAnimationStart")
    }

    override fun onAnimationRepeat(animation: Animation) {
        Log.d("////", "onAnimationRepeat")
    }

    override fun onAnimationEnd(animation: Animation) {
        Log.d("////", "onAnimationEnd")
        // Pass the Intent to switch to other Activity
    }
})
binding.myTextView.startAnimation(animation)
Goodwin answered 20/5, 2023 at 6:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.