RecyclerView notifyItemRemoved 的坑
来源:互联网 发布:软件空下载 编辑:程序博客网 时间:2024/06/05 12:13
RecyclerView 的 notifyItemRemoved 方法 可以 实现 带动画的 删除
先设置
recyclerView.setItemAnimator(new DefaultItemAnimator()); 这样可以带有 添加和删除的动画
然后 更新的时候 不要使用 notifyDataSetChanged 方法 使用 notifyItemRemoved(pos)方法
可以实现动画添加删除 其中动画的可以使用很多
高兴的是,github上已经有很多类似的项目了,这里我们直接引用下:动画,大家自己下载查看。
提供了SlideInOutLeftItemAnimator,SlideInOutRightItemAnimator,
SlideInOutTopItemAnimator,SlideInOutBottomItemAnimator等动画效果。
但是 有一个问题 如果 单纯只是这样 删除的时候会 崩溃 数组越界 是因为 这个方法 没有更新 adapter的数据集 只是更新了界面
调用一下notifyItemRangeChanged方法 绑定一下数据集就可以了
remove:把数据从list中remove掉,
notifyItemRemoved:显示动画效果
notifyItemRangeChanged:对于被删掉的位置及其后range大小范围内的view进行重新onBindViewHolder
代码应该这样写
imageList.remove(pos); notifyItemRemoved(pos); notifyItemRangeChanged(pos,imageList.size());
0 0
- RecyclerView notifyItemRemoved 的坑
- RecyclerView里notifyItemRemoved的坑
- RecyclerView里notifyItemRemoved的坑
- RecyclerView里notifyItemRemoved的坑
- RecyclerView里notifyItemRemoved的坑
- RecyclerView的notifyItemRemoved()方法删除条目问题
- RecyclerView.Adapter notifyItemRemoved postion错位的问题
- RecyclerView关于notifyItemRemoved的那点小事
- RecyclerView关于notifyItemRemoved的那点小事!
- RecyclerView关于notifyItemRemoved的那点小事
- recyclerview notifyItemRemoved报错
- RecyclerView使用notifyItemRemoved错乱
- RecyclerView如何使用正确notifyItemRemoved
- recyclerView.notifyItemRemoved数据索引混乱
- 使用recyclerView的notifyItemRemoved()和remove数据的时候出现的
- Android RecyclerView使用notifyItemRemoved()移除数据时数据错乱
- 安卓开发 RecycleView 中notifyItemRemoved遇到的那些坑, IndexOutOfIndexException、删除错乱,数组越界等终极解决方案,多人亲测可行
- XRecyclerView的notifyItemRemoved 删除item时position的问题
- Tomcat知识点
- 第八章 8-3 在状态报告上使用计时器
- python-内置函数map()
- An internal error occurred during: "Launching on Tomcat 7.x"
- Spring核心之loC
- RecyclerView notifyItemRemoved 的坑
- STM8S_003_TIM定时中断
- Redis配置
- http协议
- 声声慢
- spring系列(一)——简介和IOC
- [core:warn] [pid 10] AH00098: pid file /var/run/apache2/apache2.pid overwritten -- Unclean shutdown
- Struts2第四篇【请求数据自动封装、Action得到域对象】
- 六.Spring AOP浅析