GridCol
柵格子組件,必須作為柵格容器組件([GridRow])的子組件使用。
說(shuō)明:
開(kāi)發(fā)前請(qǐng)熟悉鴻蒙開(kāi)發(fā)指導(dǎo)文檔 :[gitee.com/li-shizhen-skin/harmony-os/blob/master/README.md
]
該組件從API Version 9開(kāi)始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
子組件
可以包含單個(gè)子組件。
接口
GridCol(option?:{span?: number | GridColColumnOption, offset?: number | GridColColumnOption, order?: number | GridColColumnOption})
從API version 9開(kāi)始,該接口支持在ArkTS卡片中使用。
參數(shù)名 | 類(lèi)型 | 必填 | 說(shuō)明 |
---|---|---|---|
span | number | [GridColColumnOption] | 否 |
offset | number | [GridColColumnOption] | 否 |
order | number | [GridColColumnOption] | 否 |
說(shuō)明:
span
、offset
、order
屬性按照xs
、sm
、md
、lg
、xl
、xxl
的順序具有“繼承性”,未設(shè)置值的斷點(diǎn)將會(huì)從前一個(gè)斷點(diǎn)取值。在不同寬度設(shè)備類(lèi)型上的默認(rèn)值為:
參數(shù)斷點(diǎn) xs sm md lg xl xxl span 2 2 3 3 4 4 offset 2 2 3 5 5 5 order 20 20 20 3 3 3
屬性
參數(shù)名 | 類(lèi)型 | 必填 | 說(shuō)明 |
---|---|---|---|
span | number | GridColColumnOption | 否 |
gridColOffset | number | GridColColumnOption | 否 |
order | number | GridColColumnOption | 否 |
GridColColumnOption
用于自定義指定在不同寬度設(shè)備類(lèi)型上,柵格子組件占據(jù)的柵格數(shù)量單位。
從API version 9開(kāi)始,該接口支持在ArkTS卡片中使用。
參數(shù)名 | 參數(shù)類(lèi)型 | 必填 | 參數(shù)描述 |
---|---|---|---|
xs | number | 否 | 在最小寬度類(lèi)型設(shè)備上,柵格子組件占據(jù)的柵格數(shù)量單位。 |
sm | number | 否 | 在小寬度類(lèi)型設(shè)備上,柵格子組件占據(jù)的柵格數(shù)量單位。 |
md | number | 否 | 在中等寬度類(lèi)型設(shè)備上,柵格子組件占據(jù)的柵格數(shù)量單位。 |
lg | number | 否 | 在大寬度類(lèi)型設(shè)備上,柵格子組件占據(jù)的柵格數(shù)量單位。 |
xl | number | 否 | 在特大寬度類(lèi)型設(shè)備上,柵格子組件占據(jù)的柵格數(shù)量單位。 |
xxl | number | 否 | 在超大寬度類(lèi)型設(shè)備上,柵格子組件占據(jù)的柵格數(shù)量單位。 |
示例
GridRow
柵格布局可以為布局提供規(guī)律性的結(jié)構(gòu),解決多尺寸多設(shè)備的動(dòng)態(tài)布局問(wèn)題,保證不同設(shè)備上各個(gè)模塊的布局一致性。
柵格容器組件,僅可以和柵格子組件([GridCol])在柵格布局場(chǎng)景中使用。
說(shuō)明:
該組件從API Version 9開(kāi)始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
子組件
可以包含GridCol子組件。
接口
GridRow(option?: {columns?: number | GridRowColumnOption, gutter?: Length | GutterOption, breakpoints?: BreakPoints, direction?: GridRowDirection})
從API version 9開(kāi)始,該接口支持在ArkTS卡片中使用。
參數(shù):
參數(shù)名 | 類(lèi)型 | 必填 | 說(shuō)明 |
---|---|---|---|
gutter | Length | GutterOption | 否 |
columns | number | GridRowColumnOption | 否 |
eakpoints | BreakPoints | 否 | 設(shè)置斷點(diǎn)值的斷點(diǎn)數(shù)列以及基于窗口或容器尺寸的相應(yīng)參照。 |
direction | GridRowDirection | 否 | 柵格布局排列方向。 |
GutterOption
柵格布局間距類(lèi)型,用于描述柵格子組件不同方向的間距。
從API version 9開(kāi)始,該接口支持在ArkTS卡片中使用。
參數(shù)名 | 參數(shù)類(lèi)型 | 必填 | 參數(shù)描述 |
---|---|---|---|
x | Length | GridRowSizeOption | 否 |
y | Length | GridRowSizeOption | 否 |
GridRowColumnOption
柵格在不同寬度設(shè)備類(lèi)型下,柵格列數(shù)。
從API version 9開(kāi)始,該接口支持在ArkTS卡片中使用。
參數(shù)名 | 參數(shù)類(lèi)型 | 必填 | 參數(shù)描述 |
---|---|---|---|
xs | number | 否 | 在最小寬度類(lèi)型設(shè)備上,柵格容器組件的柵格列數(shù)。 |
sm | number | 否 | 在小寬度類(lèi)型設(shè)備上,柵格容器組件的柵格列數(shù)。 |
md | number | 否 | 在中等寬度類(lèi)型設(shè)備上,柵格容器組件的柵格列數(shù)。 |
lg | number | 否 | 在大寬度類(lèi)型設(shè)備上,柵格容器組件的柵格列數(shù)。 |
xl | number | 否 | 在特大寬度類(lèi)型設(shè)備上,柵格容器組件的柵格列數(shù)。 |
xxl | number | 否 | 在超大寬度類(lèi)型設(shè)備上,柵格容器組件的柵格列數(shù)。 |
GridRowSizeOption
柵格在不同寬度設(shè)備類(lèi)型下,gutter的大小。
從API version 9開(kāi)始,該接口支持在ArkTS卡片中使用。
參數(shù)名 | 參數(shù)類(lèi)型 | 必填 | 參數(shù)描述 |
---|---|---|---|
xs | Length | 否 | 在最小寬度類(lèi)型設(shè)備上,柵格子組件的間距。 |
sm | Length | 否 | 在小寬度類(lèi)型設(shè)備上,柵格子組件的間距。 |
md | Length | 否 | 在中等寬度類(lèi)型設(shè)備上,柵格子組件的間距。 |
lg | Length | 否 | 在大寬度類(lèi)型設(shè)備上,柵格子組件的間距。 |
xl | Length | 否 | 在特大寬度類(lèi)型設(shè)備上,柵格子組件的間距。 |
xxl | Length | 否 | 在超大寬度類(lèi)型設(shè)備上,柵格子組件的間距。 |
BreakPoints
設(shè)置柵格容器組件的斷點(diǎn)。
從API version 9開(kāi)始,該接口支持在ArkTS卡片中使用。
參數(shù)名 | 參數(shù)類(lèi)型 | 必填 | 參數(shù)描述 |
---|---|---|---|
value | Array | 否 | 設(shè)置斷點(diǎn)位置的單調(diào)遞增數(shù)組。 默認(rèn)值:["320vp", "600vp", "840vp"] |
reference | BreakpointsReference | 否 | 斷點(diǎn)切換參照物。 默認(rèn)值:BreakpointsReference.WindowSize |
// 啟用xs、sm、md共3個(gè)斷點(diǎn)
breakpoints: {value: ["100vp", "200vp"]}
// 啟用xs、sm、md、lg共4個(gè)斷點(diǎn),斷點(diǎn)范圍值必須單調(diào)遞增
breakpoints: {value: ["320vp", "600vp", "840vp"]}
// 啟用xs、sm、md、lg、xl共5個(gè)斷點(diǎn),斷點(diǎn)范圍數(shù)量不可超過(guò)斷點(diǎn)可取值數(shù)量-1
breakpoints: {value: ["320vp", "600vp", "840vp", "1080vp"]}
BreakpointsReference枚舉類(lèi)型
從API version 9開(kāi)始,該接口支持在ArkTS卡片中使用。
枚舉名 | 描述 |
---|---|
WindowSize | 以窗口為參照。 |
ComponentSize | 以容器為參照。 |
GridRowDirection枚舉類(lèi)型
從API version 9開(kāi)始,該接口支持在ArkTS卡片中使用。
枚舉名 | 描述 |
---|---|
Row | 柵格元素按照行方向排列。 |
RowReverse | 柵格元素按照逆序行方向排列。 |
柵格最多支持xs、sm、md、lg、xl、xxl六個(gè)斷點(diǎn),且名稱不可修改。假設(shè)傳入的數(shù)組是[n0, n1, n2, n3, n4],各個(gè)斷點(diǎn)取值如下:
斷點(diǎn) | 取值范圍 |
---|---|
xs | [0, n0) |
sm | [n0, n1) |
md | [n1, n2) |
lg | [n2, n3) |
xl | [n3, n4) |
xxl | [n4, INF) |
說(shuō)明:
- 柵格元素僅支持Row/RowReverse排列,不支持column/ColumnReverse方向排列。
- 柵格子組件僅能通過(guò)span、offset計(jì)算子組件位置與大小。多個(gè)子組件span超過(guò)規(guī)定列數(shù)時(shí)自動(dòng)換行。
- 單個(gè)元素span大小超過(guò)最大列數(shù)時(shí)后臺(tái)默認(rèn)span為最大column數(shù)。
- 新一行的Offset加上子組件的span超過(guò)總列數(shù)時(shí),將下一個(gè)子組件在新的一行放置。
- 例:Item1: GridCol({ span: 6}), Item2: GridCol({ span: 8, offset:11})
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
---|---|---|---|---|---|---|---|---|---|---|---|
°° | °° | °° | °° | °° | °° | - | - | - | - | - | - |
- | - | - | - | - | |||||||
°° | °° | °° | °° | °° | °° | °° | °° |
屬性
除支持[通用屬性]外,還支持以下屬性:
名稱 | 參數(shù)類(lèi)型 | 描述 |
---|---|---|
alignItems10+ | ItemAlign | 設(shè)置GridRow中的GridCol垂直主軸方向?qū)R方式,默認(rèn)值:ItemAlign.Start 說(shuō)明 : ItemAlign支持的枚舉:ItemAlign.Start、ItemAlign.Center、ItemAlign.End、ItemAlign.Stretch。 GridCol本身也可通過(guò)alignSelf([ItemAlign])設(shè)置自身對(duì)齊方式。當(dāng)上述兩種對(duì)齊方式都設(shè)置時(shí),以GridCol自身設(shè)置為準(zhǔn)。 從API version 10開(kāi)始,該接口支持在ArkTS卡片中使用。 |
事件
onBreakpointChange
onBreakpointChange(callback: (breakpoints: string) => void)
斷點(diǎn)發(fā)生變化時(shí)觸發(fā)回調(diào)。
從API version 9開(kāi)始,該接口支持在ArkTS卡片中使用。
參數(shù):
參數(shù)名 | 參數(shù)類(lèi)型 | 必填 | 說(shuō)明 |
---|---|---|---|
eakpoints | string | 是 | 取值為"xs" 、"sm" 、"md" 、"lg" 、"xl" 、"xxl" 。HarmonyOS與OpenHarmony鴻蒙文檔籽料:mau123789是v直接拿 |
示例
// xxx.ets
@Entry
@Component
struct GridRowExample {
@State bgColors: Color[] = [Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Pink, Color.Grey, Color.Blue, Color.Brown]
@State currentBp: string = 'unknown'
build() {
Column() {
GridRow({
columns: 5,
gutter: { x: 5, y: 10 },
breakpoints: { value: ["400vp", "600vp", "800vp"],
reference: BreakpointsReference.WindowSize },
direction: GridRowDirection.Row
}) {
ForEach(this.bgColors, (color: Color) = > {
GridCol({ span: { xs: 1, sm: 2, md: 3, lg: 4 }, offset: 0, order: 0 }) {
Row().width("100%").height("20vp")
}.borderColor(color).borderWidth(2)
})
}.width("100%").height("100%")
.onBreakpointChange((breakpoint) = > {
this.currentBp = breakpoint
})
}.width('80%').margin({ left: 10, top: 5, bottom: 5 }).height(200)
.border({ color: '#880606', width: 2 })
}
}
審核編輯 黃宇
-
組件
+關(guān)注
關(guān)注
1文章
518瀏覽量
17938 -
鴻蒙
+關(guān)注
關(guān)注
57文章
2395瀏覽量
43091
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
鴻蒙ArkTS容器組件:Scroll
鴻蒙ArkTS容器組件:SideBarContainer
![<b class='flag-5'>鴻蒙</b><b class='flag-5'>ArkTS</b><b class='flag-5'>容器</b><b class='flag-5'>組件</b>:SideBarContainer](https://file1.elecfans.com/web2/M00/EB/95/wKgZomZevfiAZTUiAAAYyNC3ogI340.png)
評(píng)論