ArkUI开发框架提供了纵向排布栅格布局容器 GridContainer ,它仅在栅格布局场景中使用。
GridContainer定义介绍
interface GridContainerInterface {
(value?: GridContainerOptions): GridContainerAttribute;
}
declare interface GridContainerOptions {
columns?: number | "auto";
sizeType?: SizeType;
gutter?: number | string;
margin?: number | string;
}
简单样例如下所示:
@Entry @Component struct ComponentTest {
@State sizeType: SizeType = SizeType.XS // 默认采用最小宽度设备类型
build() {
Column() {
GridContainer({
columns: 12, // 设置格栅布局为12列
sizeType: this.sizeType, // 设置格栅布局类型
gutter: 10, // 设置格栅布局列间距,该版本还有bug
margin: 20 // 设计格栅布局两侧间距
}) {
Row() {
Text('1')
.useSizeType({
xs: { span: 6, offset: 0 }, // Text1在xs设备上占用6列
sm: { span: 2, offset: 0 }, // Text1在sm设备上占用2列
md: { span: 2, offset: 0 }, // Text1在md设备上占用2列
lg: { span: 3, offset: 0 } // Text1在lg设备上占用3列
})
.fontSize(20)
.height(50)
.backgroundColor(0x4682B4)
.textAlign(TextAlign.Center)
Text('2')
.useSizeType({
xs: { span: 2, offset: 0 }, // Text2在xs设备上占用2列
sm: { span: 6, offset: 0 }, // Text2在sm设备上占用6列
md: { span: 2, offset: 0 }, // Text2在md设备上占用2列
lg: { span: 3, offset: 0 } // Text2在lg设备上占用3列
})
.fontSize(20)
.height(50)
.backgroundColor(0x00BFFF)
.textAlign(TextAlign.Center)
Text('3')
.useSizeType({
xs: { span: 2, offset: 0 }, // Text3在xs设备上占用2列
sm: { span: 2, offset: 0 }, // Text3在sm设备上占用2列
md: { span: 6, offset: 0 }, // Text3在md设备上占用6列
lg: { span: 3, offset: 0 } // Text3在lg设备上占用3列
})
.fontSize(20)
.height(50)
.backgroundColor(0x4682B4)
.textAlign(TextAlign.Center)
Text('4')
.useSizeType({
xs: { span: 2, offset: 0 }, // Text4在xs设备上占用2列
sm: { span: 2, offset: 0 }, // Text4在sm设备上占用2列
md: { span: 2, offset: 0 }, // Text4在md设备上占用2列
lg: { span: 3, offset: 0 } // Text4在lg设备上占用3列
})
.fontSize(20)
.height(50)
.backgroundColor(0x00BFFF)
.textAlign(TextAlign.Center)
}
}
.backgroundColor(Color.Pink)
.width('90%')
.margin({top: 10})
Row({space: 10}) {
Button('XS')
.onClick(() => {
this.sizeType = SizeType.XS
}).backgroundColor(0x317aff)
Button('SM')
.onClick(() => {
this.sizeType = SizeType.SM
}).backgroundColor(0x317aff)
Button('MD')
.onClick(() => {
this.sizeType = SizeType.MD
}).backgroundColor(0x317aff)
Button('LG')
.onClick(() => {
this.sizeType = SizeType.LG
}).backgroundColor(0x317aff)
}
.margin({top: 10})
}.width('100%')
}
}
码牛课堂也为了积极培养鸿蒙生态人才,让大家都能学习到鸿蒙开发最新的技术,针对一些在职人员、0基础小白、应届生/计算机专业、鸿蒙爱好者等人群,整理了一套纯血版鸿蒙(HarmonyOS Next)全栈开发技术的学习路线。大家可以进行参考学习:
为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计0页),希望对大家有所帮助:
《鸿蒙开发学习手册》:
如何快速入门:
开发基础知识:
- 应用基础知识
- 配置文件
- 应用数据管理
- 应用安全管理
- 应用隐私保护
- 三方应用调用管控机制
- 资源分类与访问
- 学习ArkTS语言
- ……
基于ArkTS 开发:
- Ability开发
- UI开发
- 公共事件与通知
- 窗口管理
- 媒体
- 安全
- 网络与链接
- 电话服务
- 数据管理
- 后台任务(Background Task)管理
- 设备管理
- 设备使用信息统计
- DFX
- 国际化开发
- 折叠屏系列
- ……
鸿蒙开发面试真题(含参):
大厂鸿蒙面试题::
鸿蒙开发面试大盘集篇(共计319页):
1.项目开发必备面试题
2.性能优化方向
3.架构方向
4.鸿蒙开发系统底层方向
5.鸿蒙音视频开发方向
6.鸿蒙车载开发方向
7.鸿蒙南向开发方向