onAnimationEnd is not getting called, onAnimationStart works fine

后端 未结 14 1605
情书的邮戳
情书的邮戳 2020-12-23 19:51

I\'ve a ScrollView in the PopupWindow. I\'m animating ScrollView contents using TranslateAnimation.

When animation starts, the onAnimationStart listener is called bu

相关标签:
14条回答
  • 2020-12-23 20:22

    I tried your code it's working fine at OnAnimation start and inAmimationEnd also , after duration time means after finish animation onAnimationEnd is called , so your code working fine

    TranslateAnimation anim =new TranslateAnimation(0, 0, -60, 0);
            anim.setDuration(1000);     
            anim.setAnimationListener(new Animation.AnimationListener() {
                    public void onAnimationStart(Animation a) {
                        Log.w("Start", "---- animation start listener called"  );
                    }
                    public void onAnimationRepeat(Animation a) {}
                    public void onAnimationEnd(Animation a) {
                        Log.d(" end  ","---- animation end listener called"  );
                    }
                });
                mIv.setAnimation(anim);
                mIv.startAnimation(anim);
    
    0 讨论(0)
  • 2020-12-23 20:24

    Do it like belows

    1. make animation final
    2. invoke it inside a handler
    3. listener should be instantiated once.
    4. clear animation.

    for example view.clearAnimation();

    new Hander().post(
       run() {
    final TranslateAnimation ani = new TranslateAnimation(0, 0, 0, 0);
    ani.setAnimationListener(mListener);
     }
    );
    
    private Animation.AnimationListener mListener = new Animation.AnimationListener() {
    }
    
    0 讨论(0)
提交回复
热议问题