ContentSizeFitter

Unconstrained:组件不根据布局元素调整 ,可手动修改长宽的值。
MinSize:根据布局元素的最小值来调整,不能手动修改长宽的值。
PreferredSize:根据布局元素的内容来调整,不能手动修改长宽的值。

ContentSizeFitter使用Preferred Size来设置RectTransform不能立即生效,必须要等一帧。

解决方法:LayoutRebuilder.ForceRebuildLayoutImmediate(GetCompontent<RectTransform>());

转载:http://www.xuanyusong.com/archives/4234

原文地址:https://www.cnblogs.com/Joke-crazy/p/12626763.html