1.使用Row时,左边图片宽度固定时,右边文字被挤出容器
2.使用Flex时,左边图片宽度固定时,右边文字覆盖在左侧图片容器上
@Builder
GoodsListWidget() {
List() {
ListItemGroup({ header: this.ListHead(), space: '24lpx' }) {
ForEach(this.goodsList, (item: GoodsModel) => {
ListItem() {
Row() {
Column() {
Image(item.Img)
.width('210lpx')
.height('100%')
.borderRadius('16lpx')
}
.width('210lpx')
.height('210lpx')
Column() {
Text(item.Name)
.fontSize('28lpx')
.fontWeight(FontWeight.Bold)
.textAlign(TextAlign.Start)
.border({ width: 1 })
.width('100%')
Text(item.Price + '')
.fontSize('28lpx')
.fontWeight(FontWeight.Bold)
}
.flexGrow(1)
.alignItems(HorizontalAlign.Start)
.backgroundColor(Color.Pink)
}
.width('100%')
.padding('24lpx')
.borderRadius('16lpx')
.backgroundColor(Color.White)
}
}, (item: GoodsModel) => item.ID?.toString())
}
}
.sticky(StickyStyle.Header)
.edgeEffect(EdgeEffect.None)
.width('100%')
.height('100%')
.padding({ left: '24lpx', right: '24lpx', bottom: '24lpx' })
.scrollBar(BarState.Off)
.nestedScroll({
scrollForward: NestedScrollMode.PARENT_FIRST,
scrollBackward: NestedScrollMode.SELF_FIRST
})
}
请尝试这个demo: