ts-container-griditem.md 4.4 KB
Newer Older
Z
zengyawen 已提交
1 2 3 4
# GridItem<a name="ZH-CN_TOPIC_0000001237715083"></a>

>![](../../public_sys-resources/icon-note.gif) **说明:** 
>该组件从API Version 7开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。
Z
zengyawen 已提交
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

网格容器中单项内容容器。

## 权限列表<a name="section14336424193517"></a>



## 子组件<a name="section12191193463511"></a>

可以包含子组件。

## 接口<a name="section158081656113510"></a>

GridItem\(\)

## 属性<a name="section4907201336"></a>

Z
zengyawen 已提交
22
<table><thead align="left"><tr><th class="cellrowborder" valign="top" width="19.09%" id="mcps1.1.5.1.1"><p>名称</p>
Z
zengyawen 已提交
23
</th>
Z
zengyawen 已提交
24
<th class="cellrowborder" valign="top" width="11.600000000000001%" id="mcps1.1.5.1.2"><p>参数类型</p>
Z
zengyawen 已提交
25
</th>
Z
zengyawen 已提交
26
<th class="cellrowborder" valign="top" width="7.920000000000001%" id="mcps1.1.5.1.3"><p>默认值</p>
Z
zengyawen 已提交
27
</th>
Z
zengyawen 已提交
28
<th class="cellrowborder" valign="top" width="61.39%" id="mcps1.1.5.1.4"><p>描述</p>
Z
zengyawen 已提交
29 30 31
</th>
</tr>
</thead>
Z
zengyawen 已提交
32
<tbody><tr><td class="cellrowborder" valign="top" width="19.09%" headers="mcps1.1.5.1.1 "><p>rowStart</p>
Z
zengyawen 已提交
33
</td>
Z
zengyawen 已提交
34
<td class="cellrowborder" valign="top" width="11.600000000000001%" headers="mcps1.1.5.1.2 "><p>number</p>
Z
zengyawen 已提交
35
</td>
Z
zengyawen 已提交
36
<td class="cellrowborder" valign="top" width="7.920000000000001%" headers="mcps1.1.5.1.3 "><p>-</p>
Z
zengyawen 已提交
37
</td>
Z
zengyawen 已提交
38
<td class="cellrowborder" valign="top" width="61.39%" headers="mcps1.1.5.1.4 "><p>用于指定当前元素起始行号。</p>
Z
zengyawen 已提交
39 40
</td>
</tr>
Z
zengyawen 已提交
41
<tr><td class="cellrowborder" valign="top" width="19.09%" headers="mcps1.1.5.1.1 "><p>rowEnd</p>
Z
zengyawen 已提交
42
</td>
Z
zengyawen 已提交
43
<td class="cellrowborder" valign="top" width="11.600000000000001%" headers="mcps1.1.5.1.2 "><p>number</p>
Z
zengyawen 已提交
44
</td>
Z
zengyawen 已提交
45
<td class="cellrowborder" valign="top" width="7.920000000000001%" headers="mcps1.1.5.1.3 "><p>-</p>
Z
zengyawen 已提交
46
</td>
Z
zengyawen 已提交
47
<td class="cellrowborder" valign="top" width="61.39%" headers="mcps1.1.5.1.4 "><p>用于指定当前元素终点行号。</p>
Z
zengyawen 已提交
48 49
</td>
</tr>
Z
zengyawen 已提交
50
<tr><td class="cellrowborder" valign="top" width="19.09%" headers="mcps1.1.5.1.1 "><p>columnStart</p>
Z
zengyawen 已提交
51
</td>
Z
zengyawen 已提交
52
<td class="cellrowborder" valign="top" width="11.600000000000001%" headers="mcps1.1.5.1.2 "><p>number</p>
Z
zengyawen 已提交
53
</td>
Z
zengyawen 已提交
54
<td class="cellrowborder" valign="top" width="7.920000000000001%" headers="mcps1.1.5.1.3 "><p>-</p>
Z
zengyawen 已提交
55
</td>
Z
zengyawen 已提交
56
<td class="cellrowborder" valign="top" width="61.39%" headers="mcps1.1.5.1.4 "><p>用于指定当前元素起始列号。</p>
Z
zengyawen 已提交
57 58
</td>
</tr>
Z
zengyawen 已提交
59
<tr><td class="cellrowborder" valign="top" width="19.09%" headers="mcps1.1.5.1.1 "><p>columnEnd</p>
Z
zengyawen 已提交
60
</td>
Z
zengyawen 已提交
61
<td class="cellrowborder" valign="top" width="11.600000000000001%" headers="mcps1.1.5.1.2 "><p>number</p>
Z
zengyawen 已提交
62
</td>
Z
zengyawen 已提交
63
<td class="cellrowborder" valign="top" width="7.920000000000001%" headers="mcps1.1.5.1.3 "><p>-</p>
Z
zengyawen 已提交
64
</td>
Z
zengyawen 已提交
65
<td class="cellrowborder" valign="top" width="61.39%" headers="mcps1.1.5.1.4 "><p>用于指定当前元素终点列号。</p>
Z
zengyawen 已提交
66 67
</td>
</tr>
Z
zengyawen 已提交
68
<tr><td class="cellrowborder" valign="top" width="19.09%" headers="mcps1.1.5.1.1 "><p>forceRebuild</p>
Z
zengyawen 已提交
69
</td>
Z
zengyawen 已提交
70
<td class="cellrowborder" valign="top" width="11.600000000000001%" headers="mcps1.1.5.1.2 "><p>boolean</p>
Z
zengyawen 已提交
71
</td>
Z
zengyawen 已提交
72
<td class="cellrowborder" valign="top" width="7.920000000000001%" headers="mcps1.1.5.1.3 "><p>false</p>
Z
zengyawen 已提交
73
</td>
Z
zengyawen 已提交
74
<td class="cellrowborder" valign="top" width="61.39%" headers="mcps1.1.5.1.4 "><p>用于设置在触发组件build时是否重新创建此节点。</p>
Z
zengyawen 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
</td>
</tr>
</tbody>
</table>

## 示例<a name="section8900105010439"></a>

```
@Entry
@Component
struct GridItemExample {
  @State numbers: string[] = Array.apply(null, Array(16)).map(function (item, i) { return i.toString() })

  build() {
    Column() {
      Grid() {
        GridItem() {
          Text('4')
            .fontSize(16).backgroundColor(0xFAEEE0)
            .width('100%').height('100%').textAlign(TextAlign.Center)
        }.rowStart(1).rowEnd(4)

        ForEach(this.numbers, (item) => {
          GridItem() {
            Text(item)
              .fontSize(16).backgroundColor(0xF9CF93)
              .width('100%').height('100%').textAlign(TextAlign.Center)
          }.forceRebuild(false)
        }, item => item)

        GridItem() {
          Text('5')
            .fontSize(16).backgroundColor(0xDBD0C0)
            .width('100%').height('100%').textAlign(TextAlign.Center)
        }.columnStart(1).columnEnd(5)
      }
      .columnsTemplate('1fr 1fr 1fr 1fr 1fr')
      .rowsTemplate('1fr 1fr 1fr 1fr 1fr')
      .width('90%').height(300)
    }.width('100%').margin({ top: 5 })
  }
}
```

![](figures/griditem.gif)