您的位置:首页 > 游戏 > 游戏 > 环球网广东疫情最新消息_河南工程招标网站_seo网站优化优化排名_上海培训机构排名榜

环球网广东疫情最新消息_河南工程招标网站_seo网站优化优化排名_上海培训机构排名榜

2024/10/5 21:18:35 来源:https://blog.csdn.net/zhongcongxu01/article/details/142549731  浏览:    关键词:环球网广东疫情最新消息_河南工程招标网站_seo网站优化优化排名_上海培训机构排名榜
环球网广东疫情最新消息_河南工程招标网站_seo网站优化优化排名_上海培训机构排名榜

当list设置横向布局时,list高度默认撑满没有达到预期的高度自适应,可以通过onAreaChange动态修改高度。

【修改前】

@Entry
@Component
struct Page148 {build() {Column() {List() {ForEach(['北京', '杭州', '上海'], (item: string, index: number) => {ListItem() {Text(item).fontSize(24).height(100 * (Math.floor(Math.random() * 3) + 1))//生成一个1到3 随机数,然后+100高度 测试.backgroundColor(Color.Pink).margin(10)}})}.listDirection(Axis.Horizontal).backgroundColor('#FFF1F3F5')}.width('100%').height('100%')}
}

【修改后】

@Entry
@Component
struct Page148 {@State maxItemHeight: number = -1build() {Column() {List() {ForEach(['北京', '杭州', '上海'], (item: string, index: number) => {ListItem() {Text(item).fontSize(24).height(100 * (Math.floor(Math.random() * 3) + 1))//生成一个1到3 随机数,然后+100高度 测试.backgroundColor(Color.Pink).margin(10)}.onAreaChange((oldArea: Area, newArea: Area) => {if (this.maxItemHeight < newArea.height) {this.maxItemHeight = newArea.height as number}})})}.listDirection(Axis.Horizontal).backgroundColor('#FFF1F3F5').height(this.maxItemHeight == -1 ? undefined : this.maxItemHeight)}.width('100%').height('100%')}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com