鸿蒙初开,开天辟地
今天带大家在Hello World中尝试修改对应的页面布局效果
首先,我们再添加一行Text组件,让它同时存在两行
@Entry @Component struct Index { @State message: string = 'Hello World'; build() { Row() { Column(){ Text(this.message) .id('HelloWorld') .fontSize(50) .fontWeight(FontWeight.Bold) .alignRules({ center: { anchor: '__container__', align: VerticalAlign.Center }, middle: { anchor: '__container__', align: HorizontalAlign.Center } }); Text(this.message) .id('HelloWorld') .fontSize(50) .fontWeight(FontWeight.Bold) .alignRules({ center: { anchor: '__container__', align: VerticalAlign.Center }, middle: { anchor: '__container__', align: HorizontalAlign.Center } }); }.width('100%'); } .height('100%') .width('100%'); } }build() {
Row() {
Column(){
Text(this.message)
.id('HelloWorld')
.fontSize(50)
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
});
Text(this.message)
.id('HelloWorld')
.fontSize(50)
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
});
}.width('100%');
}
.height('100%')
.width('100%');
}
事实证明Column()组件就是竖向排列的,其中的元素组件也如预期般排布了
接下来我们调整一下左右,让左右两边都有这个Hello World效果,让它们左右排布
build() {@Entry @Component struct Index { @State message: string = 'Hello World'; build() { Row() { Column(){ Text(this.message) .id('HelloWorld') .fontSize(50) .fontWeight(FontWeight.Bold) .alignRules({ center: { anchor: '__container__', align: VerticalAlign.Center }, middle: { anchor: '__container__', align: HorizontalAlign.Center } }); }.width('50%'); Column(){ Text(this.message) .id('HelloWorld') .fontSize(50) .fontWeight(FontWeight.Bold) .alignRules({ center: { anchor: '__container__', align: VerticalAlign.Center }, middle: { anchor: '__container__', align: HorizontalAlign.Center } }); }.width('50%'); }.height('100%'); } }
Row() {
Column(){
Text(this.message)
.id('HelloWorld')
.fontSize(50)
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
});
}.width('50%');
Column(){
Text(this.message)
.id('HelloWorld')
.fontSize(50)
.fontWeight(FontWeight.Bold)
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
middle: { anchor: '__container__', align: HorizontalAlign.Center }
});
}.width('50%');
}.height('100%');
}



事实证明Column()组件就是竖向排列的,其中的元素组件也如预期般排布了

被折叠的 条评论
为什么被折叠?



