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
相关问题
HarmonyOS Grid组件能否高度自适应
1152浏览 • 1回复 待解决
HarmonyOS Grid组件能否自适应内容高度?
952浏览 • 1回复 待解决
HarmonyOS Grid高度根据内容自适应
1172浏览 • 1回复 待解决
Web组件如何实现高度自适应
2057浏览 • 1回复 待解决
HarmonyOS Grid自适应高度和拖拽问题
1705浏览 • 1回复 待解决
HarmonyOS 如何实现自适应web的高度
1024浏览 • 1回复 待解决
HarmonyOS grid如何自适应宽度
1178浏览 • 1回复 待解决
HarmonyOS web组件怎么自适应高度
1107浏览 • 1回复 待解决
HarmonyOS web组件自适应高度问题
2278浏览 • 1回复 待解决
HarmonyOS 自适应组件高度问题
2405浏览 • 1回复 待解决
HarmonyOS RichText自适应高度
1155浏览 • 1回复 待解决
HarmonyOS 高度自适应
1409浏览 • 1回复 待解决
HarmonyOS Web高度自适应问题
2066浏览 • 1回复 待解决