objectAnimator.addListener 自定义事件未触发

主要是记录一下android studio 属性动画学习的遇到的问题以及解决. 

              final ImageView image = findViewById(R.id.image);
                ObjectAnimator objectAnimator =  
               bjectAnimator.ofFloat(image,"alpha",0f,1f);
                //设置动画持续时间
                objectAnimator.setDuration(2000);
                objecAnimator.start();    
             //指定重写事件回调函数
                objectAnimator.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        super.onAnimationEnd(animation);
                        image.setRotation(90);
                    }
                });
            objectAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                image.setRotation(180);
            }
        });

主要在为动画设置监听器时出现了问题,如上代码,我想在动画开始时让图片角度调整为90°,

然后结束时旋转180°。但是在模拟器上实际运行时发现只有onAnimationEnd函数触发了,而onAnimationStart函数并没有触发,理论上来说,我重定义函数的位置应该对函数的调用没有影响,但是我把代码改成下面这样:

 final ImageView image = findViewById(R.id.image);
                ObjectAnimator objectAnimator =  
               bjectAnimator.ofFloat(image,"alpha",0f,1f);
                //设置动画持续时间
                objectAnimator.setDuration(2000);
               
             //指定重写事件回调函数
                objectAnimator.addListener(new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationStart(Animator animation) {
                        super.onAnimationEnd(animation);
                        image.setRotation(90);
                    }
                });
            objectAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                image.setRotation(180);
            }
        });


         objecAnimator.start();    

即把start()函数放在onAnimationStart函数下面,onAnimationStart函数就能触发了,即在start()函数执行时,onAnimationStart函数已经是否被重写了决定了调用的函数是不是我重写的。

以上问题在我的Android Studio上出现,不知道其他人的是不是这样。

仅供参考。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值