StaggeredGridView 实现分析-首次填充过程(二)

1, 上篇分析到了第一个view成功加入listView, 在步骤3中,我们从 itemPos++ 开始,分析第二个view如何出现。

      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,


2, getNextChildDownsTop 有两个版本:

//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 或 topPadding

接下来又要回到下次循环了, 调用makeAndAddView 加入第二个child view, 

makeAndAddView(1,topPadding,true, false ), 回到上篇分析的步骤3, 带入这里的参数就完成了第二个child view的加入过程。


现在总结一下,都有哪些变量发生了变化:

mColumnBottoms[] , size = 2, 如图,

mPositionData[] ,size = 2, 分别记录了数据项(来自adapter)0、1 对应的view的 column、 heightRatio

141303_4ubR_255456.png

接下来 nextTop值 是 上图中的 mColumnBottoms[0],  itemPos 自增为2, 继续重复这一过程,不断用新的child view 将listView填满 。

142822_1X0f_255456.png


转载于:https://my.oschina.net/u/255456/blog/344815

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值