美文网首页
view绘制:layout布局阶段&FrameLayout

view绘制:layout布局阶段&FrameLayout

作者: 崽子猪 | 来源:发表于2019-05-31 14:44 被阅读0次

Layout阶段主要根据得到View的测量的宽高来确定我们View最终摆放的位置

View --- > Layout(int l,int t,int r,int b)

setOpticalFrame(l,t,r,b) : setFrame(l,t,r,b)

判断位置是否发生改变,如果发生改变就在这两个方法当中选择其中一个进行重新布局

setOpticalFrame(l,t,r,b) : setFrame(l,t,r,b)
Layout --- > onLayout(changed,l,t,r,b)

对View进行局部变换


onLayout
ViewGroup ---> OnLayout()

点开这个方法发现它是空的所以我们去ViewGroup当中找到OnLayout()发现ViewGroup当中这个方法是抽象的,因为不同的布局管理器有着不同的布局方式,所以需要我们不同的Layout类去继承重写ViewGroup中的OnLayout()方法


ViewGroup ---> OnLayout()
FreamLayout ---> onLayout()

在这个父View当中摆放所有子View的一个过程


FreamLayout ---> onLayout()

onLayout()---> layoutChidren()

parentLeft:表示当前的View为我们View显示的左边界(子View显示区域的左边到我们父View左边的距离)

parentLeft/right/top/bottom一样

会通过for(int i=0;i<count;i++)这个循环来完成子View的布局
然后通过 child.getVisibility() 来判断这个View是否为可见的 如果这个子View不为空的话就会执行下面的方法 对子View进行布局
**child.getLayoutParams() **:获取View的LayoutParams
child.getMeasuredWidth():获取宽
childLeft:最终子View的左边缘距离我们父边缘的距离
childTop:最终子View的上边缘距离我们父边缘的距离

for(int i=0;i<count;i++)

根据子View的LayoutGravity对childLeft和childTop做出不同的调整


switch(absoluteGravity&.........

child.layout(l,t,r,b):调用子View的layout对子View进行参数设置

child.layout()

相关文章

网友评论

      本文标题:view绘制:layout布局阶段&FrameLayout

      本文链接:https://www.haomeiwen.com/subject/vojwtctx.html