Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear Animation Listeners set by NineOldAndroids?

I am trying to have a view animated in my app and am using NineOldAndroid for animations.
The desired effect is to fade the view out and then set it's visibility to gone so that it doesn't get clicked while invisible. Here is How I do it.

ViewPropertyAnimator.animate(view).alpha(0).setListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                view.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });

The problem here is that the listener above sticks with the view and when I try to fade it in again the listener gets called again resulting the view to be GONE upon appearing.

ViewPropertyAnimator.animate(enterGallery).alpha(1);

How can I clear the listener after the view visibility is set to GONE in the first piece of code?

like image 780
2hamed Avatar asked Feb 10 '23 19:02

2hamed


1 Answers

I found the solution and it would be to pass null as listener when making the view VISIBLE.

ViewPropertyAnimator.animate(view).alpha(1).setListener(null);
like image 155
2hamed Avatar answered Feb 15 '23 10:02

2hamed