以下是简单的采用自适应布局中的占比能力均分子组件宽度或者采用父组件的横向对齐格式为FlexAlign.SpaceAround实现子组件自适应均分父组件宽度的方案。其余最佳适配实践方案可参考官方示例。
@Entry
@Component
struct Divide1 {
build() {
Row() {
Text('1')
.backgroundColor('#F1F3F5')
.layoutWeight(1)
.textAlign(TextAlign.Center)
.height(50);
Text('2')
.backgroundColor('#E5E5EA')
.layoutWeight(1)
.textAlign(TextAlign.Center)
.height(50);
Text('3')
.backgroundColor('#D1D1D6')
.layoutWeight(1)
.textAlign(TextAlign.Center)
.height(50);
}
.width('100%');
}
} @Entry
@Component
struct Divide2 {
build() {
Row() {
Text('1')
.height(50)
.width(100)
.backgroundColor('#F1F3F5');
Text('2')
.height(50)
.width(100)
.backgroundColor('#E5E5EA');
Text('3')
.height(50)
.width(100)
.backgroundColor('#D1D1D6');
}
.justifyContent(FlexAlign.SpaceAround)
.width('100%');
}
}