ts-universal-attributes-z-order.md 1.3 KB
Newer Older
Z
zengyawen 已提交
1
# Z-order Control
Z
zengyawen 已提交
2 3


E
esterzhou 已提交
4
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
Z
zengyawen 已提交
5 6 7 8
> This attribute is supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.


## Required Permissions
Z
zengyawen 已提交
9 10 11

None

Z
zengyawen 已提交
12

Z
zengyawen 已提交
13 14 15
## Attributes


E
esterzhou 已提交
16
  | Name | Type | Default Value | Description | 
Z
zengyawen 已提交
17
| -------- | -------- | -------- | -------- |
E
esterzhou 已提交
18
| zIndex | number | 0 | Hierarchy of sibling components in a container. A larger z-order value indicates a higher display level. | 
Z
zengyawen 已提交
19 20 21 22 23


## Example

  
Z
zengyawen 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
```
@Entry
@Component
struct ZIndexExample {
  build() {
    Column() {
      Stack() {
        // Components are stacked. By default, the component defined later is on the top.
        Text('first child, zIndex(2)')
          .size({width: '40%', height: '30%'}).backgroundColor(0xbbb2cb)
          .zIndex(2)
        // The default value is 0.
        Text('second child, default zIndex(0)')
          .size({width: '90%', height: '80%'}).backgroundColor(0xd2cab3).align(Alignment.TopStart)
        Text('third child, zIndex(1)')
          .size({width: '70%', height: '50%'}).backgroundColor(0xc1cbac).align(Alignment.TopStart)
          .zIndex(1)
      }
    }.width('100%').height(200)
  }
}
```

Z
zengyawen 已提交
47
![en-us_image_0000001257058443](figures/en-us_image_0000001257058443.png)