ListView视图缓存错位问题
来源:互联网 发布:淘宝公司需要交税吗 编辑:程序博客网 时间:2024/05/16 23:38
由于之前写Scroller应用:ListView滑动删除遇到Item视图错位问题,观察发现第1item位置改变后,第1+10的item布局也跟着改变,如果使用ScrollView+ListView,把ListView的高度测量出来然后再滑动就不会出现错位问题,继续查看之所以间隔10,我屏幕上显示10条数据,这个就涉及到getCount()和getChildCount()问题,进一步追踪发现应该是ListView视图缓存的问题,其实这个问题跟数据是一样的,不过我们在Adapter的getView中根据不同的position设置不同的数据,这个动作是实时改变的,getChildCount()返回的是内存中的item数目,getCount()返回的是实际的数据数目,ListView中实际的item布局也就是getChildCount()的值,如果采用测量ListView设置其高度的话,那getChildCount()等于getCount(),在ListView中有这么一段代码
// Pull all children into the RecycleBin. // These views will be reused if possible final int firstPosition = mFirstPosition; final RecycleBin recycleBin = mRecycler; // reset the focus restoration View focusLayoutRestoreDirectChild = null; // Don't put header or footer views into the Recycler. Those are // already cached in mHeaderViews; if (dataChanged) { for (int i = 0; i < childCount; i++) { recycleBin.addScrapView(getChildAt(i), firstPosition+i); } } else { recycleBin.fillActiveViews(childCount, firstPosition); }firstPosition是第一个可见的item的位置,recycleBin.addScrapView(getChildAt(i), firstPosition+i);缓存隐藏item的时候,都是使用getChildCount()内的现有的View视图,所以解决错位问题必须采用位置的标记来处理,而且标记也不能在自定义的item中进行,必须在外部例如自定义ListView中记录。在Scroller应用:ListView滑动删除中采用的是规避的方式,滑动就关闭之前打开的item,看了QQ消息列表也是滑动的话就隐藏删除按钮,我不知道是否规避这个问题,因为ListView内存的item数据一般大于屏幕可见的item数据,所以即使屏幕大也看不到。
0 0
- ListView视图缓存错位问题
- ListView数据错位问题
- Listview错位的问题
- 关于ListView 错位的问题
- listview解决图片错位问题
- ListView图片加载错位问题
- ListView 闪烁 图片错位问题
- Android ListView 视图缓存
- Listview视图缓存优化
- Android ListView错位问题之背景色错位
- Android ListView加载图片错位的问题
- listview 加载图片 的错位问题
- Android ListView异步加载图片错位问题
- 关于ListView的滑动错位问题
- 使用ImageLoad开源库ListView图片错位问题
- ListView中解决图片错位问题
- ListView的CheckBox的错位问题
- listview嵌套gridview,数据错位问题
- 巧用环境变量执行命令
- 法国和家庭已截图语言
- dghtyjt6uik68uik
- Unity3D中随机函数的应用
- FAQ03127 MTK修改代码编绎命令
- ListView视图缓存错位问题
- C++中关于虚函数与虚函数表的理解
- 北大青鸟代码---asp.net初学者宝典
- 设计模式之观察者模式-Observer
- poj 1466 Girls and Boys (最大独立集)
- 对编码的认识与想法
- libvirt架构及源码分析
- 初学C#_4
- 算法导论7.4-5