1, 上篇分析到了第一个view成功加入listView, 在步骤3中,咱们从 itemPos++ 开始,分析第二个view如何出现。java
while ((nextTop < end || hasSpaceDown()) && pos < mItemCount) { // TODO : add selection support // 目前不支持select , 因此selected一概为false makeAndAddView(itemPos, nextTop, true, false); itemPos++; nextTop = getNextChildDownsTop(itemPos); // = child.getBottom(); }
此时 itemPos 的值是1,ide
2, getNextChildDownsTop 有两个版本:this
//ExtendableListView.java protected int getNextChildDownsTop(final int itemPosition) { final int count = getChildCount(); return count > 0 ? getChildAt(count - 1).getBottom() : 0; } //StaggeredGridView.java /** * Get the top for the next child down in our view * (maybe a column across) so we can fill down. */ @Override protected int getNextChildDownsTop(final int itemPos) { if (isHeaderOrFooter(itemPos)) { return super.getNextChildDownsTop(itemPos); } else { return getHighestPositionedBottom(); //we assume there is no header view , so this branch is executed } }
getHighestPositionedBottom前面已经用到过,咱们假设有两列, 第一列已经有了一个child view, 因为第二列仍是空的,因此mColumnBottoms[1]的值是listView的 topPadding (没有设置padding的话就是 0 了), 因此最终 获得的nextTop的值是 0 或 topPaddingspa
接下来又要回到下次循环了, 调用makeAndAddView 加入第二个child view, code
makeAndAddView(1,topPadding,true, false ), 回到上篇分析的步骤3, 带入这里的参数就完成了第二个child view的加入过程。ci
如今总结一下,都有哪些变量发生了变化:get
mColumnBottoms[] , size = 2, 如图,it
mPositionData[] ,size = 2, 分别记录了数据项(来自adapter)0、1 对应的view的 column、 heightRatioio
接下来 nextTop值 是 上图中的 mColumnBottoms[0], itemPos 自增为2, 继续重复这一过程,不断用新的child view 将listView填满 。class