UIElements 包括一个布局引擎,可根据布局和样式属性定位视觉元素。该布局引擎是 Yoga 开源项目,实现了名为 Flexbox 的 HTML/CSS 布局系统的子集。
要开始使用 Yoga 和 Flexbox,请参阅以下外部资源:
默认情况下,所有视觉元素都是布局的一部分。布局具有以下默认行为:
UIElements 包括标准 UI 控件的内置控件,如按钮、开关、文本字段或标签。这些内置控件具有影响其布局的样式。
下面列出了有关如何使用布局引擎的技巧:
设置 width
和 height
来定义元素的大小。
使用 flexGrow
属性(USS 格式为:flex-grow: <value>;
)为元素分配灵活的大小。当元素的大小由其同级决定时,flexGrow
属性的值用作加权。
将 flexDirection
属性设置为 row
(USS 格式为:flex-direction: row;
)以切换到水平布局。
使用相对定位根据元素的原始布局位置来偏移元素。
使用绝对定位相对于父位置矩形放置元素。在这种情况下不会影响其同级和父项的布局
如果一个元素具有由 API 分配的 layout.position
属性,则该元素将自动设置为 absolute
。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.