AI浪潮下,企业如何挑选内训机构?四大核心维度与高分机构推荐
2026/6/23 3:32:10
子元素从上到下纵向排列,最常用根布局。
ets
Column({ space: 10 }) { Text("第一行") Text("第二行") } .width("100%").padding(20)核心:space设置内部元素间距。
子元素从左到右横向排列,常用于一行多按钮、单选框。
ets
Row({ space: 15 }) { Button("左") Button("右") }通过锚点规则,让组件相对其他组件 / 容器摆放,适合精准定位。
ets
RelativeContainer() { Text("顶部文本") .alignRules({ top: { anchor: "__container", align: VerticalAlign.Top } }) } .width("100%").height(300)组件上下堆叠,后写的元素覆盖在前写元素上方,适合轮播遮罩、角标。
ets
Stack() { Image($r("app.media.banner")).width(300).height(150) Text("活动标签").fontColor("#fff") }自适应分配空间,可横向 / 纵向,自动均分宽度,适配多列列表。
ets
Flex({ wrap: FlexWrap.Wrap }) { Text("1").width("30%").height(60).backgroundColor("#eee") Text("2").width("30%").height(60).backgroundColor("#eee") Text("3").width("30%").height(60).backgroundColor("#eee") }build方法内只能放一个根布局(Column/Row/Stack 等);space、justifyContent、alignItems控制元素对齐;