W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
從API Version 7開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
柵格布局的列寬、列間距由距離最近的GridContainer父組件決定。使用柵格屬性的組件樹上至少需要有1個(gè)GridContainer容器組件。
名稱 | 參數(shù)類型 | 描述 |
---|---|---|
useSizeType(deprecated) | { xs?: number | { span: number, offset: number }, sm?: number | { span: number, offset: number }, md?: number | { span: number, offset: number }, lg?: number | { span: number, offset: number } } | 設(shè)置在特定設(shè)備寬度類型下的占用列數(shù)和偏移列數(shù),span: 占用列數(shù); offset: 偏移列數(shù)。 當(dāng)值為number類型時(shí),僅設(shè)置列數(shù), 當(dāng)格式如{"span": 1, "offset": 0}時(shí),指同時(shí)設(shè)置占用列數(shù)與偏移列數(shù)。 - xs: 指設(shè)備寬度類型為SizeType.XS時(shí)的占用列數(shù)和偏移列數(shù)。 - sm: 指設(shè)備寬度類型為SizeType.SM時(shí)的占用列數(shù)和偏移列數(shù)。 - md: 指設(shè)備寬度類型為SizeType.MD時(shí)的占用列數(shù)和偏移列數(shù)。 - lg: 指設(shè)備寬度類型為SizeType.LG時(shí)的占用列數(shù)和偏移列數(shù)。 |
gridSpan | number | 默認(rèn)占用列數(shù),指useSizeType屬性沒有設(shè)置對應(yīng)尺寸的列數(shù)(span)時(shí),占用的柵格列數(shù)。 說明: 設(shè)置了柵格span屬性,組件的寬度由柵格布局決定。 默認(rèn)值:1 |
gridOffset | number | 默認(rèn)偏移列數(shù),指useSizeType屬性沒有設(shè)置對應(yīng)尺寸的偏移(offset)時(shí), 當(dāng)前組件沿著父組件Start方向,偏移的列數(shù),也就是當(dāng)前組件位于第n列。 說明: - 配置該屬性后,當(dāng)前組件在父組件水平方向的布局不再跟隨父組件原有的布局方式,而是沿著父組件的Start方向偏移一定位移。 - 偏移位移 = (列寬 + 間距)* 列數(shù)。 - 設(shè)置了偏移(gridOffset)的組件之后的兄弟組件會根據(jù)該組件進(jìn)行相對布局,類似相對布局。 默認(rèn)值:0 |
- // xxx.ets
- @Entry
- @Component
- struct GridContainerExample1 {
- build() {
- Column() {
- Text('useSizeType').fontSize(15).fontColor(0xCCCCCC).width('90%')
- GridContainer() {
- Row({}) {
- Row() {
- Text('Left').fontSize(25)
- }
- .useSizeType({
- xs: { span: 1, offset: 0 }, sm: { span: 1, offset: 0 },
- md: { span: 1, offset: 0 }, lg: { span: 2, offset: 0 }
- })
- .height("100%")
- .backgroundColor(0x66bbb2cb)
- Row() {
- Text('Center').fontSize(25)
- }
- .useSizeType({
- xs: { span: 1, offset: 0 }, sm: { span: 2, offset: 1 },
- md: { span: 5, offset: 1 }, lg: { span: 7, offset: 2 }
- })
- .height("100%")
- .backgroundColor(0x66b6c5d1)
- Row() {
- Text('Right').fontSize(25)
- }
- .useSizeType({
- xs: { span: 1, offset: 0 }, sm: { span: 1, offset: 3 },
- md: { span: 2, offset: 6 }, lg: { span: 3, offset: 9 }
- })
- .height("100%")
- .backgroundColor(0x66bbb2cb)
- }
- .height(200)
- }
- .backgroundColor(0xf1f3f5)
- .margin({ top: 10 })
- // 單獨(dú)設(shè)置組件的span和offset,在sm尺寸大小的設(shè)備上使用useSizeType中sm的數(shù)據(jù)實(shí)現(xiàn)一樣的效果
- Text('gridSpan,gridOffset').fontSize(15).fontColor(0xCCCCCC).width('90%')
- GridContainer() {
- Row() {
- Row() {
- Text('Left').fontSize(25)
- }
- .gridSpan(1)
- .height("100%")
- .backgroundColor(0x66bbb2cb)
- Row() {
- Text('Center').fontSize(25)
- }
- .gridSpan(2)
- .gridOffset(1)
- .height("100%")
- .backgroundColor(0x66b6c5d1)
- Row() {
- Text('Right').fontSize(25)
- }
- .gridSpan(1)
- .gridOffset(3)
- .height("100%")
- .backgroundColor(0x66bbb2cb)
- }.height(200)
- }
- }
- }
- }
圖1 設(shè)備寬度為SM
圖2 設(shè)備寬度為MD
圖3 設(shè)備寬度為LG
圖4 單獨(dú)設(shè)置gridSpan和gridOffset在特定屏幕大小下的效果與useSizeType效果一致
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: