HarmonyOS Grid高度根据内容自适应

grid 宽度设置后,如何设置可以让高度根据内容自适应。

HarmonyOS
2024-12-18 17:04:41
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
shlp

Grid组件根据rowsTemplate、columnsTemplate属性的设置情况,有三种布局模式,请参考:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/ts-container-grid-V5

demo参考如下:

计算展示的行数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('tag', arr.join(' '))
  return arr.join(' ');
}

getCategoryViewHeight() {
  return `${130 * this.getCategoryRowCount()}vp`;
}

Grid() {
}
.height(this.getCategoryViewHeight())
.columnsTemplate('1fr 1fr')
.rowsTemplate(this.getCategoryRowTmpl())
分享
微博
QQ
微信
回复
2024-12-18 19:00:17
相关问题
HarmonyOS List高度根据内容自适应
503浏览 • 1回复 待解决
HarmonyOS Grid组件能否自适应内容高度?
309浏览 • 1回复 待解决
List水平布局如何根据内容自适应高度
1063浏览 • 1回复 待解决
HarmonyOS Grid组件能否高度自适应
350浏览 • 1回复 待解决
HarmonyOS Grid自适应高度和拖拽问题
925浏览 • 1回复 待解决
Grid组件如何实现高度自适应
3621浏览 • 1回复 待解决
HarmonyOS web的高度自适应内容高度
610浏览 • 1回复 待解决
HarmonyOS 高度自适应
659浏览 • 1回复 待解决
HarmonyOS RichText自适应高度
370浏览 • 1回复 待解决
HarmonyOS grid如何自适应宽度
447浏览 • 1回复 待解决
HarmonyOS webview高度不能自适应
227浏览 • 1回复 待解决
HarmonyOS RelativeContainer无法自适应高度
817浏览 • 1回复 待解决
HarmonyOS RichText能否自适应高度
300浏览 • 1回复 待解决
HarmonyOS Web高度自适应问题
1152浏览 • 1回复 待解决