HarmonyOS 关于组件height百分比显示问题

假设一个Column组件中有A B C 三个组件, A的height为height(20),B的height('80%'), 那么C的高度如何显示表示(目前C的默认高度并不等于父组件的剩余高度),height('20%'-20),语法上并不行。

HarmonyOS
2024-09-26 11:55:13
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

可以使用flex布局,demo如下:

@Component  
@Entry  
struct Index {  
  build() {  
    Column() {  
      Flex({ direction: FlexDirection.Column}){  
        Text('你好').width('100%').height(20).backgroundColor(Color.Gray)  
        Text('我好').width('100%').height('80%').backgroundColor(Color.Orange)  
        Text('大家好').flexBasis(1).flexShrink(1).flexGrow(1).backgroundColor(Color.Blue).width('100%')  
      }  
  
    }  
    .width('100%')  
    .height('100%')  
    .backgroundColor(Color.Pink)  
  }  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
分享
微博
QQ
微信
回复
2024-09-26 15:47:40
相关问题
HarmonyOS 关于 margin 设置百分问题
698浏览 • 1回复 待解决
HarmonyOS ArkTS百分变量设置
589浏览 • 1回复 待解决
HarmonyOS 关于CustomDialog显示层级问题
630浏览 • 1回复 待解决
HarmonyOS 关于Abiliaty显示方向的问题
561浏览 • 1回复 待解决
HarmonyOS 关于Navigation组件问题
1464浏览 • 1回复 待解决
HarmonyOS 关于Web组件适配问题
619浏览 • 1回复 待解决
HarmonyOS 关于video组件问题
883浏览 • 1回复 待解决
HarmonyOS 关于stack组件手势遮盖问题
523浏览 • 1回复 待解决