在继承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, 然后一级一级的向下传递。

 

 

 

相关文章:

  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2021-03-09
  • 2021-12-11
猜你喜欢
  • 2021-12-09
  • 2022-12-23
  • 2021-04-16
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
相关资源
相似解决方案