对onLayout()方法的理解

在继承ViewGroup时,必须重写onLayout()方法

 onLayout:when this view should assign a size and position to all of its children

a. 属于ViewGroup的方法,用来为当前ViewGroup的子元素的位置和大小(大小是layout分配给本元素的显示空间大小,与本元素的大小可能不一样)

b. View的layout方法体中会调用onLayout

调试的时候会发现自定义的view,其中onLayout()方法会被调用两次,

这个onLayout是由父View触发当前View layout方法的时候, 的一个callback. 当布局里面任何一个View的frame改变了, 都会触发最上层的View的onLayout, 然后一级一级的向下传递。

Conquer Android开发者群95426703,Q:1532507234, 1532507234@qq.com,
原文地址:https://www.cnblogs.com/renkangke/p/3049861.html