1、LayoutManager的流程
实现generateDefaultLayoutParams方法
主体方法:onLayoutChildren
具体方法
detachAndScrapAttachedViews 回收view到ScrapCache空间,这是为了防止重复加载控件
getViewForPosition 获取子view
addView添加子view
measureChildWithMargins 测量子view
getWidth获取父宽度
getHeight获取父高度
getDecoratedMeasuredWidth获取测量的宽度
getDecoratedMeasuredHeight获取测量的高度
layoutDecoratedWithMargins 将带margin的宽度和高度放置到父控件中
2、ViewGrounp流程
实现generateDefaultLayoutParams方法
主题方法一:onMeasure测量父控件,子控件,设置父控件的宽高
MeasureSpec.getMode父控件宽高的模式
MeasureSpec.getSize 父控件的宽高
getChildAt 获取子view
measureChildWithMargins 测量带margin的子view
measuredWidth获取测量的宽度
measuredHeight获取测量的高度
setMeasuredDimension设置父控件的宽高
主体方法二:onLayout,用于具体的放置子view
getChildAt获取子view
measuredWidth获取子view的测量宽度
measuredHeight获取子view 的测量高度
getLayoutParams获取子view的布局参数
layout通过传入子view的上下左右的值,放置子view
查看这两个自定义,其实是相似的都是通过测量子view,然后将子view在父控件中放置