A组件的高度由B组件决定,但是B组件的高度不确定,类似的问题有解决方式么?

B的子组件内容有多有少,高度不确定。怎么让A的高度跟B一样。

HarmonyOS
2024-10-08 11:31:13
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

可以先获取宽高,详情可以参考:https://blog.csdn.net/Mayism123/article/details/135285794

组件能否设置最小/最大高度可以写个函数。

getLastMinHeight(minHeight: number, count: number, gapLength: number, countHeight: number): number {  
  const gapHeightSum = count ? (count - 1) * gapLength : 0  
  const countHeightSum = count * countHeight  
  
  console.log(`${gapHeightSum}${countHeightSum}`)  
  
  if ((countHeightSum + gapHeightSum) > minHeight) {  
    return countHeightSum + gapHeightSum  
  } else {  
    return minHeight  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
分享
微博
QQ
微信
回复
2024-10-08 16:18:08
相关问题
HarmonyOS Web组件高度问题
1108浏览 • 1回复 待解决
HarmonyOS web组件自适应高度问题
1726浏览 • 1回复 待解决
HarmonyOS 自适应父组件高度问题
1798浏览 • 1回复 待解决
HarmonyOS 有没有Toast类似的组件
981浏览 • 1回复 待解决
HarmonyOS 设置list组件高度
514浏览 • 1回复 待解决
气泡组件有推荐实现方式
1340浏览 • 1回复 待解决
HarmonyOS 如何来设定web组件高度
477浏览 • 1回复 待解决
HarmonyOS Grid-GridItem组件高度咨询
538浏览 • 1回复 待解决
HarmonyOS 输入法高度是如何确定
1270浏览 • 1回复 待解决