ConstraintLayout有多少次测量它的每个孩子?

Jus*_*ins 5 android android-layout android-view android-constraintlayout

RelativeLayout测量其所有孩子两次.这可能会导致性能问题.约束布局是否仅测量其子项一次?

Bri*_*ell 7

ConstraintLayout 最多需要两次测量通过.

如果查看ConstraintLayout源代码,您会看到它的onMeasure()方法首先在internalMeasureChildren()实用程序方法中测量其子代.接下来,它评估一些约束.最后,在循环中第二次ConstraintLayout调用child.measure()它的子节点.

来源:反编译类文件,因为此时源不可用.

  • 它每次都不会测量两次.对于宽度可以改变的儿童,它只需要测量两次(因为它可能影响高度). (3认同)