36、鸿蒙/布局/自适应列表开关
2024-07-26 本文已影响0人
圆梦人生
- 案例:实现列表开关
- 思路:布局为左右,使用行布局(Row),左侧为文本自适应,右侧为开关Toggle,效果如下:

代码
@Component
export struct LayoutWeightToggle {
build() {
Column(){
Row(){
Text('开启低电量模式')
.layoutWeight(1)
.fontColor('#ccc')
Toggle({ isOn: false, type: ToggleType.Switch })
}.width('100%')
.justifyContent(FlexAlign.SpaceBetween)
.height(50)
.backgroundColor(Color.White)
.padding({ left:16, right:16 })
}.width('100%')
.height('100%')
.backgroundColor(Color.Gray)
}
}