HarmonyOS 使用List的警告:You are advised to initialize the width and height attributes of the List component.?

如题:HarmonyOS 使用List的警告:You are advised to initialize the width and height attributes of the List component.?

阅读 1.2k
1 个回答

问题场景

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组件就可以和兄弟组件按权重分配父组件尺寸

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进