When the parent component is in full screen, the child component will expand to fill the available space by default. If you apply left and right margins, the child component may exceed the screen's boundaries, causing the margins to be ineffective. You can use the constraintSize attribute to limit the maximum width and height of the child component. The sample code is as follows:
@Entry
@Component
struct Index {
@State message: string = 'Hello World';
build() {
Row() {
Column() {
Text(this.message)
.fontSize(50)
.fontWeight(FontWeight.Bold)
.textAlign(TextAlign.Center)
.width('100%')
.constraintSize({ maxWidth: '100%' })
.backgroundColor(Color.Blue)
.margin({ left: 50, right: 50 })
}
.width('100%')
}
.height('100%')
}
} Reference
constraintSize in Size