• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Size
2
3The size attributes set the width, height, and margins of a component.
4
5>  **NOTE**
6>
7>  The initial APIs of this module are supported since API version 7. Updates will be marked with a superscript to indicate their earliest API version.
8>
9>  When a component's size is set by percentage, the actual size is calculated based on the size of the nearest ancestor node with a fixed size.
10
11## width
12
13width(value: Length): T
14
15Sets the width of the component. By default, the width required to fully hold the component content is used. If the width of the component is greater than that of the parent container, the component will be drawn beyond the parent container scope.
16
17Since API version 10, this API supports the calc calculation feature.
18
19**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets.
20
21**Atomic service API**: This API can be used in atomic services since API version 11.
22
23**System capability**: SystemCapability.ArkUI.ArkUI.Full
24
25**Parameters**
26
27| Name  | Type                          | Mandatory  | Description                 |
28| ----- | ---------------------------- | ---- | ------------------- |
29| value | [Length](ts-types.md#length) | Yes   | Width of the component to set.<br>Unit: vp|
30
31**Return value**
32
33| Type| Description|
34| --- | --- |
35|  T | Current component.|
36
37>  **NOTE**
38>
39>  - In the [TextInput](./ts-basic-components-textinput.md) component, setting **width** to **auto** means that the width adapts to the width of the text content.
40>
41>  - In the [AlphabetIndexer](./ts-container-alphabet-indexer.md) component, setting **width** to **auto** means that the width adapts to the maximum width of index entries.
42
43## height
44
45height(value: Length): T
46
47Sets the height of the component. By default, the height required to fully hold the component content is used. If the height of the component is greater than that of the parent container, the component will be drawn beyond the parent container scope.
48
49Since API version 10, this API supports the calc calculation feature.
50
51**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets.
52
53**Atomic service API**: This API can be used in atomic services since API version 11.
54
55**System capability**: SystemCapability.ArkUI.ArkUI.Full
56
57**Parameters**
58
59| Name  | Type                          | Mandatory  | Description                 |
60| ----- | ---------------------------- | ---- | ------------------- |
61| value | [Length](ts-types.md#length) | Yes   | Height of the component to set.<br>Unit: vp|
62
63**Return value**
64
65| Type| Description|
66| --- | --- |
67|  T | Current component.|
68
69>  **NOTE**
70>
71>  In the [Row](./ts-container-row.md), [Column](./ts-container-column.md), and [RelativeContainer](./ts-container-relativecontainer.md) components, setting **width** and **height** to **auto** means that the size adapts to the size of their child components.
72
73## width<sup>15+</sup>
74
75width(widthValue: Length | LayoutPolicy): T
76
77Sets the width of the component or its horizontal layout policy. By default, the component uses the width required for its content. If the width of the component is greater than that of the parent container, the component will be drawn beyond the parent container scope.
78
79**Widget capability**: This API can be used in ArkTS widgets since API version 15.
80
81**Atomic service API**: This API can be used in atomic services since API version 15.
82
83**System capability**: SystemCapability.ArkUI.ArkUI.Full
84
85**Parameters**
86
87| Name  | Type                          | Mandatory  | Description                 |
88| ----- | ---------------------------- | ---- | ------------------- |
89| widthValue | [Length](ts-types.md#length) \|  [LayoutPolicy](ts-types.md#layoutpolicy15) | Yes   | Width of the component to set.<br>Unit: vp<br>The [Flex](./ts-container-flex.md), [Row](./ts-container-row.md), [Column](./ts-container-column.md) and [Stack](./ts-container-stack.md) components support all parameters in [LayoutPolicy](ts-types.md#layoutpolicy15).<br> The [RelativeContainer](./ts-container-relativecontainer.md), [FolderStack](./ts-container-folderstack.md), [Divider](./ts-basic-components-divider.md), and [Blank](./ts-basic-components-blank.md) components support the **matchParent** parameter in [LayoutPolicy](ts-types.md#layoutpolicy15).|
90
91**Return value**
92
93| Type| Description|
94| --- | --- |
95|  T | Current component.|
96
97## height<sup>15+</sup>
98
99height(heightValue: Length | LayoutPolicy): T
100
101Sets the height of the component or its vertical layout policy. By default, the component uses the height required for its content. If the height of the component is greater than that of the parent container, the component will be drawn beyond the parent container scope.
102
103**Widget capability**: This API can be used in ArkTS widgets since API version 15.
104
105**Atomic service API**: This API can be used in atomic services since API version 15.
106
107**System capability**: SystemCapability.ArkUI.ArkUI.Full
108
109**Parameters**
110
111| Name  | Type                          | Mandatory  | Description                 |
112| ----- | ---------------------------- | ---- | ------------------- |
113| heightValue | [Length](ts-types.md#length) \|  [LayoutPolicy](ts-types.md#layoutpolicy15) | Yes   | Height of the component to set.<br>Unit: vp<br>The [Flex](./ts-container-flex.md), [Row](./ts-container-row.md), [Column](./ts-container-column.md) and [Stack](./ts-container-stack.md) components support all parameters in [LayoutPolicy](ts-types.md#layoutpolicy15).<br> The [RelativeContainer](./ts-container-relativecontainer.md), [FolderStack](./ts-container-folderstack.md), [Divider](./ts-basic-components-divider.md), and [Blank](./ts-basic-components-blank.md) components support the **matchParent** parameter in [LayoutPolicy](ts-types.md#layoutpolicy15).<br> The [GridRow](./ts-container-gridrow.md) and [GridCol](./ts-container-gridcol.md) components support the **fixAtIdealSize** parameter in [LayoutPolicy](ts-types.md#layoutpolicy15).|
114
115**Return value**
116
117| Type| Description|
118| --- | --- |
119|  T | Current component.|
120
121## size
122
123size(value: SizeOptions): T
124
125Sets the width and height of the component.
126
127Since API version 10, this API supports the calc calculation feature.
128
129**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets.
130
131**Atomic service API**: This API can be used in atomic services since API version 11.
132
133**System capability**: SystemCapability.ArkUI.ArkUI.Full
134
135**Parameters**
136
137| Name  | Type                             | Mandatory  | Description               |
138| ----- | ------------------------------- | ---- | ----------------- |
139| value | [SizeOptions](#sizeoptions) | Yes   | Size of the component to set.<br>Unit: vp|
140
141**Return value**
142
143| Type| Description|
144| --- | --- |
145|  T | Current component.|
146
147## padding
148
149padding(value: Padding | Length | LocalizedPadding): T
150
151Sets the padding of the component.
152
153Since API version 10, this API supports the calc calculation feature.
154
155**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets.
156
157**Atomic service API**: This API can be used in atomic services since API version 11.
158
159**System capability**: SystemCapability.ArkUI.ArkUI.Full
160
161**Parameters**
162
163| Name  | Type                                      | Mandatory  | Description                                      |
164| ----- | ---------------------------------------- | ---- | ---------------------------------------- |
165| value | [Padding](ts-types.md#padding) \|  [Length](ts-types.md#length) \|   [LocalizedPadding](ts-types.md#localizedpadding12)<sup>12+</sup>| Yes   | Padding of the component to set.<br>When the parameter is of the **Length** type, the four paddings take effect.<br>Default value: **0**<br>Unit: vp<br>When **padding** is set to a percentage, the width of the parent container is used as the basic value.|
166
167**Return value**
168
169| Type| Description|
170| --- | --- |
171|  T | Current component.|
172
173## margin
174
175margin(value: Margin | Length | LocalizedMargin): T
176
177Sets the margin of the component.
178
179Since API version 10, this API supports the calc calculation feature.
180
181**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets.
182
183**Atomic service API**: This API can be used in atomic services since API version 11.
184
185**System capability**: SystemCapability.ArkUI.ArkUI.Full
186
187**Parameters**
188
189| Name| Type                                                        | Mandatory    | Description                                                        |
190| ------ | ------------------------------------------------------------ | -------- | ------------------------------------------------------------ |
191| value  | [Margin](ts-types.md#margin) \| [Length](ts-types.md#length) \| [LocalizedMargin](ts-types.md#localizedmargin12)<sup>12+</sup> | Yes| Margin of the component to set.<br>When the parameter is of the **Length** type, the four margins take effect.<br>Default value: **0**<br>Unit: vp<br>When **margin** is set to a percentage, the width of the parent container is used as the basic value. When child components are laid out along the cross axis of the [Row](./ts-container-row.md), [Column](./ts-container-column.md), or [Flex](./ts-container-flex.md) container, the cross axis size of the child components and the margins add up to the total size of the container.<br>For example, if the width of the **Column** container is 100, the width of the child component is 50, the left margin is 10, and the right margin is 20, then the actual horizontal offset of the child component is 10.|
192
193**Return value**
194
195| Type| Description|
196| --- | --- |
197|  T | Current component.|
198
199## safeAreaPadding<sup>14+</sup>
200
201safeAreaPadding(paddingValue: Padding | LengthMetrics | LocalizedPadding): T
202
203Sets the safe area padding. This allows the container to add a component-level safe area for its child components to extend into. This attribute can be dynamically set using [attributeModifier](ts-universal-attributes-attribute-modifier.md#attributemodifier).
204
205**Widget capability**: This API can be used in ArkTS widgets since API version 14.
206
207**Atomic service API**: This API can be used in atomic services since API version 14.
208
209**System capability**: SystemCapability.ArkUI.ArkUI.Full
210
211**Parameters**
212
213| Name  | Type                                      | Mandatory  | Description                                      |
214| ----- | ---------------------------------------- | ---- | ---------------------------------------- |
215| paddingValue | [Padding](ts-types.md#padding) \|  [LengthMetrics](../js-apis-arkui-graphics.md#lengthmetrics12) \|   [LocalizedPadding](ts-types.md#localizedpadding12)| Yes   | Safe area padding.<br>Default value: **0**<br>Unit: vp|
216
217**Return value**
218
219| Type| Description|
220| --- | --- |
221|  T | Current component.|
222
223> **NOTE**
224>
225> When parent and ancestor containers define component-level safe areas, child components can detect and utilize these areas, referred to as Accumulated Safe Area Expansion (SAE), which represents the maximum extendable length in each direction. When ancestor containers have contiguous **safeAreaPadding** (undivided by margin, border, or padding), SAE accumulates recursively outward until no adjacent outer **safeAreaPadding** exists or the recursion extends beyond the page container. System-level avoid areas (status bar, navigation bar, notch areas, and more**) are treated as the page container's inherent safeAreaPadding** and participate in SAE calculations. For details about the avoid areas, see [expandSafeArea](./ts-universal-attributes-expand-safe-area.md).
226>
227>These component-level safe areas can be leveraged by combining with other attributes. For example, setting the [ignoreLayoutSafeArea](./ts-universal-attributes-expand-safe-area.md) attribute on a child component allows it to extend its layout into the SAE region.
228
229## layoutWeight
230
231layoutWeight(value: number | string): T
232
233Sets the weight of the component during layout. A component with this attribute set is allocated space along the main axis of its parent container ([Row](./ts-container-row.md), [Column](./ts-container-column.md), or [Flex](./ts-container-flex.md)) based on its specified weight.
234
235**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets.
236
237**Atomic service API**: This API can be used in atomic services since API version 11.
238
239**System capability**: SystemCapability.ArkUI.ArkUI.Full
240
241**Parameters**
242
243| Name  | Type                        | Mandatory     | Description                                      |
244| ----- | -------------------------- | ------- | ---------------------------------------- |
245| value | number \| string | Yes| Layout weight of the component.<br>When the parent container size is determined:<br>Elements without **layoutWeight** or with **layoutWeight** set to **0** take precedence in occupying space.<br> The remaining space on the main axis is then allocated proportionally among elements with a **layoutWeight** value greater than 0, ignoring their own size settings.<br>Default value: **0**<br>**NOTE**<br>This parameter is only effective in [Row](./ts-container-row.md), [Column](./ts-container-column.md), and [Flex](./ts-container-flex.md) container components.<br>The value can be a number greater than or equal to 0 or a string that can be converted to a number.<br>If any child component in a container has the **layoutWeight** attribute set to a value greater than 0, then child components will no longer be laid out based on **flexShrink** and **flexGrow**.|
246
247**Return value**
248
249| Type| Description|
250| --- | --- |
251|  T | Current component.|
252
253## constraintSize
254
255constraintSize(value: ConstraintSizeOptions): T
256
257Sets the constraint size of the component, which is used to limit the size range during component layout.
258
259Since API version 10, this API supports the calc calculation feature.
260
261**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets.
262
263**Atomic service API**: This API can be used in atomic services since API version 11.
264
265**System capability**: SystemCapability.ArkUI.ArkUI.Full
266
267**Parameters**
268
269| Name  | Type                                      | Mandatory  | Description                                      |
270| ----- | ---------------------------------------- | ---- | ---------------------------------------- |
271| value | [ConstraintSizeOptions](ts-types.md#constraintsizeoptions) | Yes   | Constraint size of the component to set. **constraintSize** takes precedence over **width** and **height**. See **Impact of constraintSize on width/height**.<br>Default value:<br>{<br>minWidth: 0,<br>maxWidth: Infinity,<br>minHeight: 0,<br>maxHeight: Infinity<br>}<br>Unit: vp<br>|
272
273**Return value**
274
275| Type| Description|
276| --- | --- |
277|  T | Current component.|
278
279**Impact of constraintSize(minWidth/maxWidth/minHeight/maxHeight) on width/height**
280
281| Default Value                                     | Result                                      |
282| ---------------------------------------- | ---------------------------------------- |
283| \ | width=MAX(minWidth,MIN(maxWidth,width))<br>height=MAX(minHeight,MIN(maxHeight,height)) |
284| maxWidth, maxHeight| width=MAX(minWidth,width)<br>height=MAX(minHeight,height) |
285| minWidth, minHeight| width=MIN(maxWidth,width)<br>height=MIN(maxHeight,height) |
286| width, height| If minWidth < maxWidth, the layout logic of the component takes effect, and the value range of **width** is [minWidth, maxWidth]. Otherwise, width = MAX(minWidth, maxWidth).<br>If minHeight < maxHeight, the layout logic of the component takes effect, and the value range of **height** is [minHeight, maxHeight]. Otherwise, height = MAX (minHeight, maxHeight).|
287| width and maxWidth; height and maxHeight| width = minWidth<br>height = minHeight |
288| width and minWidth; and height and minHeight| The layout logic of the component takes effect, and the value of **width** cannot be greater than that of **maxWidth**.<br>The layout logic of the component takes effect, and the value of **height** cannot be greater than that of **maxHeight**.|
289| minWidth and maxWidth; minHeight and maxHeight| The width of the component is initially determined by the value of **width**, and it may be adjusted based on other layout attributes.<br>The height of the component is initially determined by the value of **height**, and it may be adjusted based on other layout attributes.|
290| width, minWidth, and maxWidth| The layout restrictions passed by the parent container are used for layout.|
291| height, minHeight, and maxHeight| The layout restrictions passed by the parent container are used for layout.|
292
293## SizeOptions
294
295Describes the width and height of a component during layout.
296
297**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets.
298
299**Atomic service API**: This API can be used in atomic services since API version 11.
300
301| Name  | Type                                      | Mandatory  | Description                                      |
302| ----- | ---------------------------------------- | ---- | ---------------------------------------- |
303| width  | [Length](ts-types.md#length) | No| Component width.|
304| height | [Length](ts-types.md#length) | No| Component height.|
305
306## ConstraintSizeOptions
307
308Describes the size constraints of a component during layout.
309
310**Widget capability**: Since API version 9, this feature is supported in ArkTS widgets.
311
312**Atomic service API**: This API can be used in atomic services since API version 11.
313
314| Name  | Type                                      | Mandatory  | Description                                      |
315| ----- | ---------------------------------------- | ---- | ---------------------------------------- |
316| minWidth  | [Length](ts-types.md#length) | No| Minimum width of the component.|
317| maxWidth  | [Length](ts-types.md#length) | No| Maximum width of the component.|
318| minHeight | [Length](ts-types.md#length) | No| Minimum height of the component.|
319| maxHeight | [Length](ts-types.md#length) | No| Maximum height of the component.|
320
321>  **NOTE**
322>
323>  In the [Row](./ts-container-row.md), [Column](./ts-container-column.md), and [RelativeContainer](./ts-container-relativecontainer.md) components, setting **width** and **height** to **auto** means that the size adapts to the size of their child components. In the [TextInput](./ts-basic-components-textinput.md) component, setting **width** to **auto** means that the width adapts to the width of the text content.
324
325## Example
326
327### Example 1: Setting the Component Width, Height, Margin, and Padding
328
329This example demonstrates how to set the width, height, padding, and margin of a component.
330
331```ts
332// xxx.ets
333@Entry
334@Component
335struct SizeExample {
336  build() {
337    Column({ space: 10 }) {
338      Text('margin and padding:').fontSize(12).fontColor(0xCCCCCC).width('90%')
339      Row() {
340        // Width: 80; height: 80; margin: 20 (blue area); top, bottom, left, and right paddings: 5, 15, 10, and 20 (white area)
341        Row() {
342          Row()
343          .size({ width: '100%', height: '100%' })
344          .backgroundColor(Color.Yellow)
345        }
346        .width(80)
347        .height(80)
348        .padding({ top: 5, left: 10, bottom: 15, right: 20 })
349        .margin(20)
350        .backgroundColor(Color.White)
351      }.backgroundColor(Color.Blue)
352
353      Text('constraintSize')
354        .fontSize(12)
355        .fontColor(0xCCCCCC)
356        .width('90%')
357      Text('this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text.this is a Text')
358        .width('90%')
359        .constraintSize({ maxWidth: 200 })
360
361      Text('layoutWeight')
362        .fontSize(12)
363        .fontColor(0xCCCCCC)
364        .width('90%')
365      // When the container size is determined, the component occupies the space along the main axis based on the layout weight, and the component size setting is ignored.
366      Row() {
367        // Weight 1: The component occupies 1/3 of the remaining space along the main axis.
368        Text('layoutWeight(1)')
369          .size({ width: '30%', height: 110 }).backgroundColor(0xFFEFD5).textAlign(TextAlign.Center)
370          .layoutWeight(1)
371        // Weight 2: The component occupies 2/3 of the remaining space along the main axis.
372        Text('layoutWeight(2)')
373          .size({ width: '30%', height: 110 }).backgroundColor(0xF5DEB3).textAlign(TextAlign.Center)
374          .layoutWeight(2)
375        // If layoutWeight is not set, the component is rendered based on its own size setting.
376        Text('no layoutWeight')
377          .size({ width: '30%', height: 110 }).backgroundColor(0xD2B48C).textAlign(TextAlign.Center)
378      }
379      .size({ width: '90%', height: 140 })
380      .backgroundColor(0xAFEEEE)
381      // calc calculation feature
382      Text('calc:')
383        .fontSize(12)
384        .fontColor(0xCCCCCC)
385        .width('90%')
386      Text('calc test')
387        .fontSize(50)
388        .fontWeight(FontWeight.Bold)
389        .backgroundColor(0xFFFAF0)
390        .textAlign(TextAlign.Center)
391        .margin('calc(25vp*2)')
392        // If width or height is set to a percentage, the width or height of the parent container are used as the basic value.
393        .size({ width: 'calc(90%)', height: 'calc(50vp + 10%)' })
394    }
395    .width('100%')
396    .margin({ top: 5 })
397  }
398}
399```
400
401![size](figures/size.png)
402
403### Example 2: Using LocalizedPadding and LocalizedMargin Types
404
405This example demonstrates how to use **LocalizedPadding** and **LocalizedMargin** types to define the **padding** and **margin** attributes.
406
407```ts
408// xxx.ets
409import { LengthMetrics } from '@kit.ArkUI'
410
411@Entry
412@Component
413struct SizeExample {
414  build() {
415    Column({ space: 10 }) {
416      Text('margin and padding:')
417        .fontSize(12)
418        .fontColor(0xCCCCCC)
419        .width('90%')
420      Row() {
421        // Set the width to 80, height to 80, top, bottom, start, and end paddings to 40, 20, 30, and 10, respectively (blue area), and top, bottom, start, and end margins to 5, 15, 10, and 20, respectively (white area).
422        Row() {
423          Row()
424            .size({ width: '100%', height: '100%' })
425            .backgroundColor(Color.Yellow)
426        }
427        .width(80)
428        .height(80)
429        .padding({
430          top: LengthMetrics.vp(5),
431          bottom: LengthMetrics.vp(15),
432          start: LengthMetrics.vp(10),
433          end: LengthMetrics.vp(20)
434        })
435        .margin({
436          top: LengthMetrics.vp(40),
437          bottom: LengthMetrics.vp(20),
438          start: LengthMetrics.vp(30),
439          end: LengthMetrics.vp(10)
440        })
441        .backgroundColor(Color.White)
442      }
443      .backgroundColor(Color.Blue)
444    }
445    .width('100%')
446    .margin({ top: 5 })
447  }
448}
449```
450
451The following shows how the example is represented with left-to-right scripts.
452
453![size](figures/size-ltr.png)
454
455The following shows how the example is represented with right-to-left scripts.
456
457![size](figures/size-rtl.png)
458
459### Example 3: Setting Safe Area
460
461This example demonstrates how to set a component-level safe area for a container.
462
463```ts
464// xxx.ets
465import { LengthMetrics } from '@kit.ArkUI';
466
467@Entry
468@Component
469struct SafeAreaPaddingExample {
470  build() {
471    Column() {
472      Column() {
473        Column()
474          .width("100%")
475          .height("100%")
476          .backgroundColor(Color.Pink)
477      }
478      .width(200)
479      .height(200)
480      .backgroundColor(Color.Yellow)
481      .borderWidth(10)
482      .padding(10)
483      .safeAreaPadding(LengthMetrics.vp(40))
484    }
485    .height('100%')
486    .width('100%')
487  }
488}
489```
490
491![safeAreaPaddingExample](figures/safeAreaPaddingExample.png)
492
493### Example 4: Using attributeModifier to Dynamically Set a Safe Area
494
495This example demonstrates how to use **attributeModifier** to dynamically set a component-level safe area for a container.
496
497```ts
498// xxx.ets
499class MyModifier implements AttributeModifier<CommonAttribute> {
500  applyNormalAttribute(instance: CommonAttribute): void {
501    instance.safeAreaPadding({
502      left: 10,
503      top: 20,
504      right: 30,
505      bottom: 40
506    })
507  }
508}
509
510@Entry
511@Component
512struct SafeAreaPaddingExample {
513  @State modifier: MyModifier = new MyModifier()
514
515  build() {
516    Column() {
517      Column() {
518        Column()
519          .width("100%")
520          .height("100%")
521          .backgroundColor(Color.Pink)
522      }
523      .width(200)
524      .height(200)
525      .backgroundColor(Color.Yellow)
526      .borderWidth(10)
527      .padding(10)
528      .attributeModifier(this.modifier)
529    }
530    .height('100%')
531    .width('100%')
532  }
533}
534```
535
536![safeAreaPaddingModifierExample](figures/safeAreaPaddingModifierExample.png)
537
538### Example 5: Setting the Layout Policy
539
540This example demonstrates how to set the layout policy for a container's size.
541
542```ts
543// xxx.ets
544@Entry
545@Component
546struct LayoutPolicyExample {
547  build() {
548    Column() {
549      Column() {
550        // When matchParent is effective, the current component's size is equal to its parent component's content area size (180x180 vp) and not subject to its own constraintSize (150x150 vp), so the current component's size is 180x180 vp.
551        Text("matchParent")
552        Flex()
553          .backgroundColor('rgb(0, 74, 175)')
554          .width(LayoutPolicy.matchParent)
555          .height(LayoutPolicy.matchParent)
556          .constraintSize({ maxWidth: 150, maxHeight: 150 })
557
558        // When wrapContent is effective, the current component's size is equal to its child component size (300x300 vp), but it cannot exceed the parent component's content size (180x180 vp) and is subject to its own constraintSize (250x250 vp), so the current component's size is 180x180 vp.
559        Text("wrapContent")
560        Row() {
561          Flex()
562            .width(300)
563            .height(300)
564        }
565        .backgroundColor('rgb(39, 135, 217)')
566        .width(LayoutPolicy.wrapContent)
567        .height(LayoutPolicy.wrapContent)
568        .constraintSize({ maxWidth: 250, maxHeight: 250 })
569
570        // When fixAtIdealSize is effective, the current component's size is equal to its child component size (300x300 vp), it can exceed the parent component's content size (180x180 vp) but is subject to its own constraintSize (250x250 vp), so the current component's size is 250x250 vp.
571        Text("fixAtIdealSize")
572
573        Row() {
574          Flex()
575            .width(300)
576            .height(300)
577        }
578        .backgroundColor('rgb(240, 250, 255)')
579        .width(LayoutPolicy.fixAtIdealSize)
580        .height(LayoutPolicy.fixAtIdealSize)
581        .constraintSize({ maxWidth: 250, maxHeight: 250 })
582      }
583      .width(200)
584      .height(200)
585      .padding(10)
586    }
587    .width("100%")
588    .height("100%")
589  }
590}
591```
592
593![layoutPolicyExample](figures/layoutPolicy_demo.jpg)
594