跳到主要内容

<pc-layout-group>

<pc-layout-group> 添加布局组,将子实体元素排为行、列或网格,并可拉伸或收缩以适应空间。

用法

属性​

属性类型默认值说明
alignmentVector2"0 1"未填满组时的整体对齐,从左下 0 0 到右上 1 1,默认左上
enabledBoolean(布尔)"true"组件启用状态
height-fittingEnum(枚举)"none"高度适配:"none" | "stretch" | "shrink" | "both",详见下文
orientationEnum(枚举)"horizontal""horizontal" 排成行,"vertical" 排成列
paddingVector4"0 0 0 0"组内部边距,顺序为左、下、右、上
reverse-xBoolean(布尔)"false"是否从右向左排列
reverse-yBoolean(布尔)"true"是否从上到下排列。Y 轴向上,因此默认反转使列和网格行从顶部开始,设为 false 可改为从底部向上
spacingVector2"0 0"X 为同行子项间距,Y 为同列子项或网格行间距
width-fittingEnum(枚举)"none"宽度适配:"none" | "stretch" | "shrink" | "both",详见下文
wrapBoolean(布尔)"false"超出时换行形成网格,垂直布局则换列
适配

none 保持尺寸;stretch 拉伸填满但不超过上限;shrink 收缩但不低于下限;both 按需选择。沿布局方向按 <pc-layout-child> 比例分摊,横向于布局方向则各自适配。启用 wrap 后先换行再适配,因此 both 表现为 stretch。详见适配。

示例​

垂直列表自动排列,首行在上方。可增大 spacing、设 reverse-y="false" 从下向上堆叠,或添加新行。orientation="horizontal" 会横向排列并可能溢出,设置 width-fitting="both" 可让它们缩小均分宽度:

实时示例
<pc-app>
<pc-scene>
<pc-entity name="camera">
<pc-camera clear-color="#1d1f2b"></pc-camera>
</pc-entity>
<pc-entity name="ui">
<pc-screen screen-space="true" scale-mode="blend" reference-resolution="640 320"></pc-screen>
<pc-entity name="list">
<pc-element type="group" anchor="0.5 0.5 0.5 0.5" pivot="0.5 0.5" width="260" height="220"></pc-element>
<pc-layout-group orientation="vertical" alignment="0 1" spacing="0 8"
padding="10 10 10 10" width-fitting="stretch"></pc-layout-group>

<pc-entity name="row-1">
<pc-element type="image" width="240" height="50" color="#ff8a3c"></pc-element>
</pc-entity>
<pc-entity name="row-2">
<pc-element type="image" width="240" height="50" color="#7ab8ff"></pc-element>
</pc-entity>
<pc-entity name="row-3">
<pc-element type="image" width="240" height="50" color="#8ce99a"></pc-element>
</pc-entity>
</pc-entity>
</pc-entity>
</pc-scene>
</pc-app>

JavaScript 接口​

可以通过 LayoutGroupComponentElement API创建和操作元素。

component 是底层 LayoutGroupComponent,就绪前为 null,其余功能可通过它访问。

另请参阅​

示例:界面布局和滚动视图。