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组件如何实现高度自适应
522浏览 • 1回复 待解决
软键盘弹出时,页面的自适应
526浏览 • 1回复 待解决
自定义弹窗大小如何自适应内容
1029浏览 • 1回复 待解决
使用Grid 组件实现选座场景
417浏览 • 1回复 待解决
嵌套ForEach不能自动适应高度
350浏览 • 1回复 待解决
grid如何怎么实现拖拽功能
407浏览 • 1回复 待解决
Grid如何实现拖拽功能
1195浏览 • 1回复 待解决
InnoDB为什么需要自适应的Hash索引?
1396浏览 • 1回复 待解决
全面屏手机的沉浸式状态栏自适应
445浏览 • 1回复 待解决
grid组件及数据懒加载
487浏览 • 1回复 待解决
如何获取组件高度,有人知道吗?
760浏览 • 1回复 待解决