Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android TranslateAnimation resets after animation

I'm creating something like a SlideDrawer but with most customization, basically the thing is working but the animation is flickering at the end.

To further explain, I got an TranslateAnimation then after this animation it returns back to the original position, if i set setFillAfter then the buttons inside the layout stops working. If i listen to onAnimationEnd and set other's layout to View.GONE the layout fickers. Judging from it is that on animation end, the view goes back to original position before the View.GONE is called.

Any advice would be awesome. Thanks

like image 694
monmonja Avatar asked Apr 16 '10 03:04

monmonja


1 Answers

Here is the actual bug related to this issue

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

like image 119
Soham Avatar answered Oct 07 '22 02:10

Soham