ts-universal-attributes-visibility.md 1.6 KB
Newer Older
Z
zengyawen 已提交
1
# Visibility
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
| visibility | Visibility | Visibility.Visible | Whether the component is shown or hidden. | 
Z
zengyawen 已提交
19 20 21 22 23


- Visibility enums
    | Name | Description | 
  | -------- | -------- |
E
esterzhou 已提交
24 25 26
  | Hidden | The component is hidden, and a placeholder is used for it in the layout. | 
  | Visible | The component is shown. | 
  | None | The component is hidden. It is not involved in the layout, and no placeholder is used for it. | 
Z
zengyawen 已提交
27 28 29 30 31


## Example

  
Z
zengyawen 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
```
@Entry
@Component
struct VisibilityExample {
  build() {
    Column() {
      Column() {
        Text('Visible').fontSize(9).width('90%').fontColor(0xCCCCCC)
        Row().visibility(Visibility.Visible).width('90%').height(80).backgroundColor(0xAFEEEE)

        Text('None').fontSize(9).width('90%').fontColor(0xCCCCCC)
        // The component is hidden and no placeholder is used.
        Row().visibility(Visibility.None).width('90%').height(80).backgroundColor(0xAFEEEE)

        Text('Hidden').fontSize(9).width('90%').fontColor(0xCCCCCC)
        // The component is hidden and a placeholder is used.
        Row().visibility(Visibility.Hidden).width('90%').height(80).backgroundColor(0xAFEEEE)
      }.width('90%').border({ width: 1 })
    }.width('100%').margin({ top: 5 })
  }
}
```

Z
zengyawen 已提交
55
![en-us_image_0000001257058421](figures/en-us_image_0000001257058421.gif)