Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android-AnimatorSet Listener does not work

im trying to set an animator listener so in the end the objectanimators something happens ! Here is my code so far :

 as=new AnimatorSet();
        as.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                om.Initialize();
                System.out.println("GotIn");
                DataBase.eaten=false;
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });

        float distance=CalcDistance();
        float angle=CalcAngle();
        tongue.setPivotX(2);
        tongue.setPivotY(0);
        rotate_tongue=ObjectAnimator.ofFloat(tongue, "rotation",0,90+angle);
        rotate_tongue.setDuration(0);
        rotate_tongue.start();
        tongue.setVisibility(View.VISIBLE);
        scale_tongue=ObjectAnimator.ofFloat(tongue,"scaleY",1.0f,1.0f*(distance/4));
        scale_tongue.setDuration(500);
        shrink_tongue=ObjectAnimator.ofFloat(tongue,"scaleY",1.0f*(distance/4),1.0f);
        shrink_tongue.setDuration(400);


        as.play(rotate_tongue).with(scale_tongue).before(shrink_tongue);
        as.start();

the problem is that the Listener doesnt actually work as nothing happens when the animatorsetend ! How to fix this ? thank you !

like image 308
MajorDanger Avatar asked Jan 20 '26 11:01

MajorDanger


1 Answers

try this, if you still haven't figured it out in 3 years :)

    as.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            // your code here
        }
    });
like image 88
thegroover Avatar answered Jan 22 '26 02:01

thegroover