Flex

Flex

1弹性布局,水平方向主轴(可切换),垂直方向交叉轴
弹性布局,水平方向主轴(可切换),垂直方向交叉轴

 1import { BasicConstants } from '../constants/BasicConstants';  2  3@Entry  4@Component  5struct Page02_GuidePage {  6 @State message: string = 'Hello World';  7  8 build() {  9 Flex({ 10 direction: FlexDirection.Row, 11 wrap: FlexWrap.Wrap 12 }) { 13 Text('1') 14 .width(100) 15 .height(100) 16 .backgroundColor(Color.Blue) 17 .flexGrow(1) 18 .flexShrink(1) 19 .alignSelf(ItemAlign.Center) 20 Text('2') 21 .width(100) 22 .height(100) 23 .backgroundColor(Color.Green) 24 .flexGrow(2) 25 } 26 .width(BasicConstants.FULL_WIDTH) 27 .height(BasicConstants.FULL_HEIGHT) 28 } 29}
import { BasicConstants } from '../constants/BasicConstants'; @Entry @Component struct Page02_GuidePage { @State message: string = 'Hello World'; build() { Flex({ direction: FlexDirection.Row, wrap: FlexWrap.Wrap }) { Text('1') .width(100) .height(100) .backgroundColor(Color.Blue) .flexGrow(1) .flexShrink(1) .alignSelf(ItemAlign.Center) Text('2') .width(100) .height(100) .backgroundColor(Color.Green) .flexGrow(2) } .width(BasicConstants.FULL_WIDTH) .height(BasicConstants.FULL_HEIGHT) } }

首页

 1import { BasicConstants } from '../constants/BasicConstants';  2  3@Entry  4@Component  5struct Page02_GuidePage {  6 @State message: string = 'Hello World';  7  8 build() {  9 Flex({ 10 direction: FlexDirection.Column, 11 alignItems: ItemAlign.Center 12 }) { 13 // logo 14 Column() { 15 Image($r('app.media.bird')) 16 .width(200) 17 .borderRadius(10) 18 } 19 .justifyContent(FlexAlign.Center) 20 .alignItems(HorizontalAlign.Center) 21 .flexGrow(1) 22 23 Image($r('app.media.startIcon')) 24 .width(28) 25 .objectFit(ImageFit.Contain) 26 27 Text('WoniuMall超市') 28 .fontColor('#66000000') 29 .fontSize(20) 30 .letterSpacing(16) 31 .margin({ 32 top: 12, 33 bottom: 136 34 }) 35 } 36 .width(BasicConstants.FULL_WIDTH) 37 .height(BasicConstants.FULL_HEIGHT) 38 } 39}
import { BasicConstants } from '../constants/BasicConstants'; @Entry @Component struct Page02_GuidePage { @State message: string = 'Hello World'; build() { Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center }) { // logo Column() { Image($r('app.media.bird')) .width(200) .borderRadius(10) } .justifyContent(FlexAlign.Center) .alignItems(HorizontalAlign.Center) .flexGrow(1) Image($r('app.media.startIcon')) .width(28) .objectFit(ImageFit.Contain) Text('WoniuMall超市') .fontColor('#66000000') .fontSize(20) .letterSpacing(16) .margin({ top: 12, bottom: 136 }) } .width(BasicConstants.FULL_WIDTH) .height(BasicConstants.FULL_HEIGHT) } }

Powered By 可尔物语

浙ICP备11005866号-12