在HarmonyOS NEXT开发中auto失效?问题描述:
List({ space: 10 }) {
ForEach(this.bookDetailsBean?.firstSubject?.split("\\/"), (item: string, index) => {
ListItem() {
Text(item)
.fontSize(14)
.fontColor("#8E8E93")
.fontWeight(FontWeight.Bold)
.backgroundColor("#f1f1f1")
.borderRadius(14)
.width('auto')
.padding({
top: 2,
bottom: 2,
left: 4,
right: 4
})
}
}, (index: number) => index + "")
}.id('_firstSubject').listDirection(Axis.Horizontal).alignRules({
left: { anchor: 'tv_book_name', align: HorizontalAlign.Start },
top: { anchor: 'tv_book_name', align: VerticalAlign.Bottom }
}).margin({ top: 15 })
发现只要这个list不设置固定的高度,list高度不会自适应Listitem的高度Harmonyos的’auto’这个属性是不是没有用?
若想要父组件跟随子组件的宽高进行自适应,需要在父组件上设置宽高为“auto”当前list横向滚动是无法自适应子组件高度
可参考如下demo: