Grid组件如何实现高度自适应

​Grid组件如何实现高度自适应

HarmonyOS
2024-01-31 09:19:12
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
mislrb

计算展示的行数rowCount,根据rowCount得出GridHeight、GridRowsTemplate

参考代码

getCategoryRowCount() { 
  return Math.ceil(this.categories.length / 2); 
} 
 
getCategoryRowTmpl() { 
  const count = this.getCategoryRowCount(); 
  const arr: string[] = new Array(count || 1).fill('1fr'); 
  console.log('tmpl ', arr.join(' ')) 
  return arr.join(' '); 
} 
 
getCategoryViewHeight() { 
  return `${130 * this.getCategoryRowCount()}vp`; 
} 
 
Grid() {} 
.height(this.getCategoryViewHeight()) 
.columnsTemplate('1fr 1fr') 
.rowsTemplate(this.getCategoryRowTmpl())
分享
微博
QQ
微信
回复
2024-02-01 17:01:53
相关问题
Web组件如何实现高度自适应
854浏览 • 1回复 待解决
HarmonyOS web组件自适应高度问题
656浏览 • 1回复 待解决
HarmonyOS 自适应组件高度问题
615浏览 • 1回复 待解决
HarmonyOS 高度自适应
35浏览 • 1回复 待解决
HarmonyOS Web高度自适应问题
380浏览 • 1回复 待解决
HarmonyOS RelativeContainer无法自适应高度
116浏览 • 1回复 待解决
HarmonyOS GridItem自适应高度问题
124浏览 • 1回复 待解决
HarmonyOS 高度自适应的问题
111浏览 • 1回复 待解决
自适应页面滚动如何实现
305浏览 • 1回复 待解决
自适应缩放布局如何实现
255浏览 • 1回复 待解决