StaggeredGridView 实现分析--首次填充过程(一)
2019独角兽企业重金招聘Python工程师标准>>>
ExtendableListView.java
1, 因为是首次layout, changed为true, childCount是 0,
//ExtendableListView.java
/*** {@inheritDoc}*/@Overrideprotected void onLayout(final boolean changed, final int l, final int t, final int r, final int b) {// super.onLayout(changed, l, t, r, b); - skipping base AbsListView implementation on purpose// haven't set an adapter yet? get to itif (mAdapter == null) {return;}if (changed) {int childCount = getChildCount();for (int i = 0; i < childCount; i++) {getChildAt(i).forceLayout();}mRecycleBin.markChildrenDirty();}// TODO get the height of the view??mInLayout = true;layoutChildren();mInLayout = false;}
2, layoutChildren, 在步骤1中可知 在layoutChildren()期间 变量mInLayout 一直为true。
在attachToWindow() 和 setAdapter(..)时 ,如果adapter不为null, 则mDataChanged 设置为 true, 所以假设这里的mDataChanged是true .
在handleDataChanged() 中, mLayoutMode 被设置为 LAYOUT_FORTCE_TOP , 所以 mFirstPosition 为 0, 然后执行 fillFromTop( top) ,假设没有headerview, 那么 top值是0 或者 listview的 topPadding值。
//ExtendableListView.java
/*** {@inheritDoc}*/@Overrideprotected void layoutChildren() {if (mBlockLayoutRequests) return;mBlockLayoutRequests = true;try {super.layoutChildren();invalidate();...int childrenTop = getListPaddingTop();int childCount = getChildCount();View oldFirst = null;// our last state so we keep our positionif (mLayoutMode == LAYOUT_NORMAL) {oldFirst = getChildAt(0);}boolean dataChanged = mDataChanged;if (dataChanged) {handleDataChanged();}...// Pull all children into the RecycleBin.// These views will be reused if possiblefinal int firstPosition = mFirstPosition;final RecycleBin recycleBin = mRecycleBin;if (dataChanged) { // true nowfor (int i = 0; i < childCount; i++) { // childcount is 0 nowrecycleBin.addScrapView(getChildAt(i), firstPosition + i);}}else {recycleBin.fillActiveViews(childCount, firstPosition);}// Clear out old viewsdetachAllViewsFromParent();recycleBin.removeSkippedScrap();switch (mLayoutMode) {case LAYOUT_FORCE_TOP: {mFirstPosition = 0;resetToTop();adjustViewsUpOrDown();fillFromTop(childrenTop);adjustViewsUpOrDown();break;}case LAYOUT_SYNC: {fillSpecific(mSyncPosition, mSpecificTop);break;}case LAYOUT_NORMAL:default: {if (childCount == 0) {fillFromTop(childrenTop);}else if (mFirstPosition < mItemCount) {fillSpecific(mFirstPosition,oldFirst == null ? childrenTop : oldFirst.getTop());}else {fillSpecific(0, childrenTop);}break;}}// Flush any cached views that did not get reused aboverecycleBin.scrapActiveViews();mDataChanged = false;mNeedSync = false;mLayoutMode = LAYOUT_NORMAL;invokeOnItemScrollListener();} finally {mBlockLayoutRequests = false;}}
2' , override:
这里将mColumnBottoms[] 和 mColumnTops[]是一样的值(每个值都是0, 或者listview的 topPadding值), 因为还没任何child view
//StaggeredGridView.java@Overrideprotected void layoutChildren() {preLayoutChildren();super.layoutChildren();}//mNeedSync 在 onRestoreInstanceState 时才会被设置为true,其他情况均为falseprivate void preLayoutChildren() {// on a major re-layout reset for our next layout passif (!mNeedSync) {Arrays.fill(mColumnBottoms, 0);}else {mNeedSync = false;}// copy the tops into the bottom// since we're going to redo a layout pass that will draw down from// the topSystem.arraycopy(mColumnTops, 0, mColumnBottoms, 0, mColumnCount);}
3, 回顾2, ExtendableListView.java, fillFromTop, 其参数是0 或者 listView的 topPadding值;mFirstPosition是0
在fillDown中, 此时 itemPos 是0 ; nextTop是顶部位置: topPadding 或 0 , 通过while循环这一过程,将有足够多的child view 被生成以填满整个listview。
//ExtendableListView.java/*** Fills the list from top to bottom, starting with mFirstPosition*/private View fillFromTop(int nextTop) {mFirstPosition = Math.min(mFirstPosition, mItemCount - 1);if (mFirstPosition < 0) {mFirstPosition = 0;}return fillDown(mFirstPosition, nextTop);}private View fillDown(int itemPos, int nextTop) { //(0,topPadding)if (DBG) Log.d(TAG, "fillDown - pos:" + pos + " nextTop:" + nextTop);View selectedView = null;int end = getHeight();if (mClipToPadding) {end -= getListPaddingBottom();}while ((nextTop < end || hasSpaceDown()) && pos < mItemCount) {// TODO : add selection support// 目前不支持select , 所以selected一律为falsemakeAndAddView(itemPos, nextTop, true, false);itemPos++;nextTop = getNextChildDownsTop(itemPos); // = child.getBottom();}return selectedView;}
4, makeAndAddView(0, 0, true, false):
执行obtainView
//ExtendableListView.java/*** Gets a view either a new view an unused view?? or a recycled view and adds it to our children*/private View makeAndAddView(int position, int y, boolean flowDown, boolean selected) {View child;onChildCreated(position, flowDown);if (!mDataChanged) {// now mDataChanged is true , so it is skipped here// Try to use an existing view for this positionchild = mRecycleBin.getActiveView(position);if (child != null) {// Found it -- we're using an existing child// This just needs to be positionedsetupChild(child, position, y, flowDown, selected, true);return child;}}// Make a new view for this position, or convert an unused view if possiblechild = obtainView(position, mIsScrap);// This needs to be positioned and measuredsetupChild(child, position, y, flowDown, selected, mIsScrap[0]);return child;}
4.1 onChildCreated( 0, true): ExtendableListView 的实现为空, 所以直接看StaggeredGridView的实现:
执行if 部分,需要看 getChildColumn 和 setPositionColumn 。
//StaggeredGridView.java@Overrideprotected void onChildCreated(final int position, final boolean flowDown) {super.onChildCreated(position, flowDown);if (!isHeaderOrFooter(position)) {// do we already have a column for this position?final int column = getChildColumn(position, flowDown);setPositionColumn(position, column); }else {setPositionIsHeaderFooter(position);}}
转载于:https://my.oschina.net/u/255456/blog/344140
StaggeredGridView 实现分析--首次填充过程(一)相关推荐
- Hyperledger Fabric从源码分析背书提案过程
在之前的文章中 Hyperledger Fabric从源码分析链码安装过程 Hyperledger Fabric从源码分析链码实例化过程 Hyperledger Fabric从源码分析链码查询与调用 ...
- Spring3.1.0实现原理分析(七).填充Bean属性,初始化Bean,登记善后处理,注册单例Bean
大家好,上篇博客我较详细分析了实例化过程,今天继续探讨实例化之后的其它步骤,分别是"填充Bean属性","初始化Bean","登记善后处理" ...
- Spring3.1.0实现原理分析(七).填充Bean属性,初始化Bean,登记善后处理,注册单例Bean...
大家好,上篇博客我较详细分析了实例化过程,今天继续探讨实例化之后的其它步骤,分别是"填充Bean属性","初始化Bean","登记善后处理" ...
- WebRTC源码分析-呼叫建立过程之五(创建Offer,CreateOffer,上篇)
目录 1. 引言 2 CreateOffer声明 && 两个参数 2.1 CreateOffer声明 2.2 参数CreateSessionDescriptionObserver 2. ...
- 【转】 浏览器分析模拟登陆过程
原文地址:http://www.crifan.com/use_ie9_f12_to_analysis_the_internal_logical_process_of_login_baidu_main_ ...
- DispatcherServlet代码分析及运行过程
DispatcherServlet代码分析及运行过程 1 首先该类有一静态语块,用以加载缺省策略. static { ClassPathResource resource =new ClassP ...
- 三十、电子商务分析与服务推荐的分析方法与过程
1. 分析方法与过程 1.1 目标 本案例的目标是对用户进行推荐,即以一定的方式将用户与物品之间建立联系.为了更好地帮助用户从海量的数据中快速发现感兴趣的网页,在目前相对单一的推荐系统上进行补充.电子 ...
- POE供电交换机技术分析及工作过程详解
PoE供电是指在以太网中透过双绞线来将电力传输到设备的技术,它无需改动现有的以太网布线基础架构,在为一些基于IP的终端传输数据信号的同时,还能为此类设备提供直流供电.透过这项技术,可以供电给网路电话. ...
- 《大话软件工程—需求分析与软件设计》,给出了分析与设计过程中需要的理论、方法、工具和标准
□ 做好一款软件从哪里开始呢?→ 客户需求的调研: □ 一款软件的价值高低由哪个环节决定呢?→ 软件的分析与设计: □ 软件顺利完成开发靠什么?→ 高效的项目管理: □ 软件开发的主要角色?→ 客户. ...
最新文章
- Coursera ML笔记 - 神经网络(Learning)
- 职场好人缘的26个细节
- EasyUI datebox 设置为按月选择
- could not extract ResultSet/could not execute statement
- 软件开发方法之敏捷开发,你用了么?
- simulink仿真之正弦波变方波
- [007]爬虫系列 | 猿人学爬虫攻防大赛 | 第四题: 雪碧图、样式干扰
- 22个常用Python包,相信你一定用的到!
- SigFox Vs. LoRa:技术和商业模式之间的比较
- 全新UI宝宝起名神器小程序源码+样式非常美观
- c语言卸载了软件打不开了,控制面板卸载不了程序,手把手教你如何处理控制面板中卸载不掉的软件...
- 5M1270ZT144A5N CPLD 980MC 6.2NS 144TQFP /5M1270ZT144C5N
- 2022年个人融资方法和工具研究报告
- Java - 对象克隆
- Meta AI:让手绘小人动起来
- 青龙面板教程(四):线报监控系统开发
- 设计需要撰写的技术文件_技术设计文件和游戏设计文件
- IP-Guard应用攻略:USBkey加密权限变更再添新技
- 私有化部署成本高?现在可以免费获取哦~
- 2.操作符流程控制循环