android animation is not finished in onAnimationEnd
Here is the actual bug related to this issue http://code.google.com/p/android-misc-widgets/issues/detail?id=8
This basically states that the onAnimationEnd method doesn't really work well when an AnimationListener is attached to an Animation
The workaround is to listen for the animation events in the view to which you were applying the animation to
For example if initially you were attaching the animation listener to the animation like this
mAnimation.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationEnd(Animation arg0) {
//Functionality here
}
});
and then applying to the animation to a ImageView like this
mImageView.startAnimation(mAnimation);
To work around this issue, you must now create a custom ImageView
public class MyImageView extends ImageView {
and then override the onAnimationEnd
method of the View class and provide all the functionality there
@Override
protected void onAnimationEnd() {
super.onAnimationEnd();
//Functionality here
}
This is the proper workaround for this issue, provide the functionality in the over-riden View -> onAnimationEnd method as opposed to the onAnimationEnd method of the AnimationListener attached to the Animation.
This works properly and there is no longer any flicker towards the end of the animation. Hope this helps.
End animation event android
You can add Animation listener to your animation object like
anim.setAnimationListener(new Animation.AnimationListener(){
@Override
public void onAnimationStart(Animation arg0) {
}
@Override
public void onAnimationRepeat(Animation arg0) {
}
@Override
public void onAnimationEnd(Animation arg0) {
}
});
Detect when animation is finished (AnimationListener)
You can check this.
Try using this code :
animation_view.addAnimatorListener(object:Animator.AnimatorListener {
override fun onAnimationRepeat(animation: Animator?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onAnimationEnd(animation: Animator?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onAnimationCancel(animation: Animator?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun onAnimationStart(animation: Animator?) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
}
Check if AnimatorSet has finished animation?
You can set an AnimatorListener on fadeinAnimation5.
This will give you an onAnimationEnd callback.
fadeinAnimation5.addListener(new AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
// ...
}
@Override
public void onAnimationRepeat(Animator animation) {
// ...
}
@Override
public void onAnimationEnd(Animator animation) {
// ...
}
@Override
public void onAnimationCancel(Animator animation) {
// ...
}
});
Or, as suggested by slott use an AnimatorListenerAdapter
fadeinAnimation5.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
// ...
}
}
onAnimationEnd is not getting called for imageview rotation animation
Because you have set INFINITE in Animation
clockAnimation.setRepeatMode(Animation.INFINITE);
it will start with infinite mode means never End
Your animation iteration updatation will notify in onAnimationRepeat
@Override
public void onAnimationRepeat(Animation animation) {
}
What document saying of method onAnimationEnd
Notifies the end of the animation. This callback is not invoked for
animations with repeat count set to INFINITE.
as per comment:
But I need animation end event. for example after 2 rotations.
for that add this lines in code
clockAnimation.setRepeatCount(2);
clockAnimation.setRepeatMode(Animation.RESTART);
AnimationListener's onAnimationEnd not triggered when postDelayed is used
A simple workaround that gets the result I wanted (that is to show the ImageView
for a few seconds and then fade it out and set it to GONE
):
Because postDelayed
was the culprit in my previous attempt, I dropped it in favor of using Animation
's setStartOffset(startOffset)
.
That means I simply delayed the animation start with the interval I used initially for postDelayed
. I still don't know why postDelayed
messed the listener of the animation.
Android, How can I know that the animation is finished?
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
}
});
Why isn't my Android animation not calling my onAnimationEnd?
You're not calling Animation#setAnimationListener
anywhere. You need to call r.setAnimationListener(PromoActivity.this)
and/or q.setAnimationListener(PromoActivity.this)
for the listener to be called.
Something to keep in mind is that you have two animations and they may not finish at exactly the same time. So you probably want to keep track of how many times your listener was called and only call startActivity
when the number of animations that was supposed to end has been reached.
Related Topics
Scale Image to Fill Imageview Width and Keep Aspect Ratio
How to Use Apply a Custom Drawable to Radiobutton
Execution Failed for Task 'App:Mergedebugresources' Crunching Cruncher....Png Failed
Why Do I Get Access Denied to Data Folder When Using Adb
How to Add a Library (Android-Support-V7-Appcompat) in Intellij Idea
How to Make an Imageview in Circular Shape
Android: Clear Cache of All Apps
How to Create Spinner-List Using Customadapter in Android
Android Webview Rem Units Scale Way to Large for Boxes
How Does the Mapping Between Android Resources and Resources Id Work
Android Animation Is Not Finished in Onanimationend
How to Change the Default Icon on the Searchview, to Be Use in the Action Bar on Android
How to Display Progress Dialog Before Starting an Activity in Android
Does Android Keep the .Apk Files? If So Where
How to Get a Working Vertical Seekbar in Android
Android Usb Host and Hidden Devices
Upload Photo to Facebook with Facebook Android Sdk in Android