【鸿蒙应用开发高手之路】02_自适应布局之拉伸能力
所谓拉伸能力,指的是:当父容器的尺寸发生变化时,增加或减少的空间全部分配给父容器内的指定子组件。
@Entry@Componentstruct GrowShrink1 { build() { Row() { Text('Wifi') .fontSize(118) Blank() .backgroundColor('#FFF24D') Toggle({ type: ToggleType.Switch, isOn: true }) .size({ width: 158, height: 98 }) } .width('100%') }}
@Entry@Componentstruct GrowShrink2 { build() { Flex() { Text('T1') .fontSize(80) .textAlign(TextAlign.Center) .backgroundColor('#F24E4E') .width(400) .height(100) .flexGrow(1) .flexShrink(3) Text('T2') .fontSize(80) .textAlign(TextAlign.Center) .backgroundColor('#FFF24D') .width(400) .height(100) .flexGrow(3) .flexShrink(1) Text('T3') .fontSize(80) .textAlign(TextAlign.Center) .backgroundColor('#45E5E1') .width(200) .height(100) .flexGrow(0) .flexShrink(0) } }}