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
相关问题
自定义弹窗大小如何自适应内容
334浏览 • 1回复 待解决
Grid如何实现拖拽功能
254浏览 • 1回复 待解决
InnoDB为什么需要自适应的Hash索引?
662浏览 • 1回复 待解决
Grid组件的scrollBar是否支持自定义
338浏览 • 1回复 待解决
组件最大和最小宽度和高度如何设置
310浏览 • 1回复 待解决
如何获取组件高度,有人知道吗?
211浏览 • 1回复 待解决
如何设置组件的最大最小宽度高度
347浏览 • 1回复 待解决
组件如何实现渐变色?
385浏览 • 1回复 待解决
List组件如何实现多列效果
137浏览 • 1回复 待解决
如何实现组件边缘的颜色渐变
218浏览 • 1回复 待解决
半模态转场如何控制固定高度
183浏览 • 1回复 待解决
Image组件如何实现双指手势放大
156浏览 • 1回复 待解决