Android ListView 源码分析
来源:互联网 发布:舟山沈四小网络考试 编辑:程序博客网 时间:2024/05/17 23:02
ListView 的源码实在太多, 重点分析ListView的几个机制
ListView的继承关系
可以看出,ListView和GridView的有极大的相似性,对ListView进行缓存,布局等操作都是在AbsListView中完成的.
RecycleBin机制
RecycleBin中的关键字段
RecycleBin将View分为两级,ActiveView和ScrapView,如果当前的view处于可见状态,将它放在ActiveView的数组中,如果ActiveView不可见了,开始将它降级为ScrapView,等待回收.
private RecyclerListener mRecyclerListener;/** * The position of the first view stored in mActiveViews. */ // 第一个ActiveView的下标,通过这个计算数组中的索引private int mFirstActivePosition;/** * Views that were on screen at the start of layout. This array is populated at the start of * layout, and at the end of layout all view in mActiveViews are moved to mScrapViews. * Views in mActiveViews represent a contiguous range of Views, with position of the first * view store in mFirstActivePosition. */ // ActiveView数组private View[] mActiveViews = new View[0];/** * Unsorted views that can be used by the adapter as a convert view. */ // ScrapView数组,因为有可能多个ViewType,所以使用二维数组进行存储private ArrayList<View>[] mScrapViews;// ViewType的数量,通过这个创建ScrapHeapprivate int mViewTypeCount;private ArrayList<View> mCurrentScrap;private ArrayList<View> mSkippedScrap;private SparseArray<View> mTransientStateViews;private LongSparseArray<View> mTransientStateViewsById;
RecycleBin中的关键方法
fillActiveViews()
RecycleBin当中使用mActiveViews
这个数组来存储View,调用这个方法后就会根据传入的参数来将ListView中的指定元素存储到mActiveViews数组当中。
/** * Fill ActiveViews with all of the children of the AbsListView. * * @param childCount The minimum number of views mActiveViews should hold * @param firstActivePosition The position of the first view that will be stored in * mActiveViews */void fillActiveViews(int childCount, int firstActivePosition) { //针对数据,调整数组大小 if (mActiveViews.length < childCount) { mActiveViews = new View[childCount]; } // 记录ActiveView的首位置 mFirstActivePosition = firstActivePosition; //noinspection MismatchedReadAndWriteOfArray final View[] activeViews = mActiveViews; for (int i = 0; i < childCount; i++) { View child = getChildAt(i); // 调整LayoutParams AbsListView.LayoutParams lp = (AbsListView.LayoutParams) child.getLayoutParams(); // Don't put header or footer views into the scrap heap // 除Header,Footer之外其他View将添加到ActiveView数组中 if (lp != null && lp.viewType != ITEM_VIEW_TYPE_HEADER_OR_FOOTER) { // Note: We do place AdapterView.ITEM_VIEW_TYPE_IGNORE in active views. // However, we will NOT place them into scrap views. activeViews[i] = child; // Remember the position so that setupChild() doesn't reset state. lp.scrappedFromPosition = firstActivePosition + i; } }}
未完 doing….
0 0
- Android ListView 源码分析
- Android源码分析之ListView
- 天天记录 - Android ListView onTouchEvent源码分析
- Android ListView源码分析 点滴记录
- ListView源码分析
- Listview部分源码分析
- Listview部分源码分析
- ListView源码分析
- ListView 源码分析
- ListView 源码分析
- 源码之ListView分析
- ListView源码分析
- ListView源码分析【转载】
- ListView源码分析
- ListView源码分析
- android ListView中view的复用源码分析
- 【进阶android】ListView源码分析——总述
- Android之ListView详解-源码分析-原理完全解析
- 生命倒计时-倒数9113日
- 遍历二叉树————非递归后续遍历
- 【课堂】【算术运算中数据类型的转换】
- java判断文件是否存在并创建文件
- 源码-Oracle数据库管理-第十七章-动态SQL语句-Part 5(动态SQL的性能优化技巧)
- Android ListView 源码分析
- adb shell命令整理之监测安卓动作
- 观《逻辑思维 -- 时间的朋友》跨年演讲
- 压缩感知中的数学知识:稀疏、范数、符号arg min
- Lucene读书笔记——3. 为应用程序添加搜索功能
- java基础三输入与输出
- POJ3237:Tree
- spark读取csv文件——scala
- laravel框架之数据库查出来的对象如何转化为数组