@Entry
@Component
struct StackLayout {
@State Align:Alignment =Alignment.Center
@State text:string = '中间'
build() {
Column() {
Text('学号123456').margin({top:20})
Stack({ alignContent:this.Align}) {
Text(this.text)
.fontSize(20)
.width(150)
.height(150)
.backgroundColor(Color.Red)
.textAlign(TextAlign.Center)
.margin(20)
}
.width('100%')
.height('50%')
Divider().width('95%').margin({top:10})
Column({space:30}){
Row({space:150}){
Column(){
Text('左上')
Radio({
value: 'a', group: 'Group1'
}).checked(false)
.onClick((value)=>{
this.Align = Alignment.TopStart
})
}
Column(){
Text('右上')
Radio({
value: 'b', group: 'Group1'
}).checked(false)
.onClick((value)=>{
this.Align = Alignment.TopEnd
})
}
}
Row(){
Column(){
Text('中间')
Radio({
value: 'c', group: 'Group1'
}).checked(false)
.onClick((value)=>{
this.Align = Alignment.Center
})
}
}
Row({space:150}){
Column(){
Text('左下')
Radio({
value: 'd', group: 'Group1'
}).checked(false)
.onClick((value)=>{
this.Align = Alignment.BottomStart
})
}
Column(){
Text('右下')
Radio({
value: 'e', group: 'Group1'
}).checked(false)
.onClick((value)=>{
this.Align = Alignment.BottomEnd
})
}
}
}.margin({top:30})
}
}
}
鸿蒙StackLayout.ets
最新推荐文章于 2024-07-25 17:45:44 发布