Open snowf07 opened 5 years ago
刚开始代码
public class ChatRoomGiftDispatchView extends FrameLayout { //多人需要显示动画分发队列 private List<List> listGiftqueue = new LinkedList<>(); //动画执行状态 private boolean mIsRunning; //是否在路径中,来区分连击 private boolean mIsPath; private Context mContext;
public void sendGift(List<GiftWrapperBean> lists) { if (null == lists || lists.size() == 0) { return; } GiftWrapperBean giftWrapperBean = lists.get(0); if (mIsRunning && cuurentMsgNo.equals(giftWrapperBean.hitMsgNo) && mIsPath == false) { //是连击,不在轨迹,执行连击动画 startTextClickAnim(giftWrapperBean.hitIndex); return; } if (mIsRunning == true) { listGiftqueue.add(lists); } else { listGiftqueue.add(lists); startAniValue(giftWrapperBean); //保存当前发送礼物的动画 gitRunningGift.clear(); gitRunningGift.addAll(listGiftqueue.get(0)); send(giftWrapperBean.pointFHead, gitRunningGift); } }
animatorSet.addListener(new Animator.AnimatorListener() {
@Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { for (int i = 0; i < listGiftqueue.size(); i++) { GiftWrapperBean bean = listGiftqueue.get(i).get(0); StringBuilder stringBuilder=new StringBuilder(); TraceLog.i("hintMsgNo="+hintMsgNo+","+bean.hitMsgNo); if (hintMsgNo.equals(bean.hitMsgNo)) { listsClick.add(listGiftqueue.get(i)); stringBuilder.append("size="+listGiftqueue.size()); //执行连击 listGiftqueue.remove(i); stringBuilder.append(",result_size="+listGiftqueue.size()); } TraceLog.i(stringBuilder.toString()); }
修改后的代码
//遍历下面元素连击 animatorSet.addListener(new Animator.AnimatorListener() {
@Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { //刷选所有路径中的自己的连击次数 List<List<GiftWrapperBean>> listsClick=new LinkedList<>(); Iterator<List<GiftWrapperBean>> iter = listGiftqueue.iterator(); while(iter.hasNext()){ List<GiftWrapperBean> list = iter.next(); GiftWrapperBean bean =list.get(0); StringBuilder stringBuilder=new StringBuilder(); TraceLog.i("hintMsgNo="+hintMsgNo+","+bean.hitMsgNo); if (hintMsgNo.equals(bean.hitMsgNo)) { listsClick.add(list); stringBuilder.append("size="+listGiftqueue.size()); //执行连击 iter.remove(); stringBuilder.append(",result_size="+listGiftqueue.size()); } TraceLog.i(stringBuilder.toString()); }
执行for()循环时,有队列进入,导致forsize没有更新导致
使用迭代的方式
刚开始代码
public class ChatRoomGiftDispatchView extends FrameLayout { //多人需要显示动画分发队列 private List<List> listGiftqueue = new LinkedList<>();
//动画执行状态
private boolean mIsRunning;
//是否在路径中,来区分连击
private boolean mIsPath;
private Context mContext;
修改后的代码
原因
执行for()循环时,有队列进入,导致forsize没有更新导致
解决
使用迭代的方式