在HarmonyOS NEXT开发中使用List的警告:You are advised to initialize the width and height attributes of the List component. <ArkTSCheck> ?问题场景如下:
List(){
ForEach(this.middleList,(data:MineItem)=>{
ListItem(){
Row(){
Image($r(data.icon))
.width(20)
Text(data.title)
.fontSize('15')
.fontColor('#000000')
.margin({left:15})
Blank()
Image($r('app.media.mine_enter'))
.width(10)
}
.width('100%')
.height(50)
}
})
}
.padding({left:15,right:15})
.width('100%')
.margin({ top:15 })
.backgroundColor('#ffffff')
.borderRadius(10)
这个警告不影响的实际的使用的,如果没有初始化高度List组件会自适应高度,但是这会导致在某些情况下显示不全的情况,可以设置一下layoutWeight属性(需要父组件设置固定高度)这样List组件就可以和兄弟组件按权重分配父组件尺寸。