animation.setAnimationListener onAnimationEnd被调用两次更新

在实现点击item后的消失动画时,发现onAnimationEnd监听器被调用了两次,导致数据删除异常。问题源于在动画取消后仍触发了一次onAnimationEnd,进而错误地执行了handler方法。需要优化动画监听逻辑,防止重复执行。
摘要由CSDN通过智能技术生成
在listview点击事件中,很多时候需要点击后产生动画效果。在adapter里加入以下代码传入相关值就行。

现要实现点击item后item的消失动画。但是Log发现会删除两条UI数据一条原始数据。参考他人代码及看源码追踪如下

动画监听方法:

private void removeListItem(View rowView, final int position) {   
          
        final Animation animation = (Animation) AnimationUtils.loadAnimation(rowView.getContext(), R.anim.floating_main_view_out);   
        animation.setAnimationListener(new AnimationListener() {   
            public void onAnimationStart(Animation animation) {}   
   
            public void onAnimationRepeat(Animation animation) {}   
   
            public void onAnimationEnd(Animation animation) {   
                Message msg = new Message();  
                msg.what = 2;  
        msg.arg1 = position;  
        mhandler.sendMessage(msg);// make the item dismiss.  
                //animation.cancel();   
            }   
        });   
        rowView.startAnimation(animation);   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值