HarmonyOS 相对布局的高度问题

相对布局使用的时候高度是100%,怎么样根据相对布局内的子组件需要的高度使用相对布局?

HarmonyOS
2024-10-15 10:23:50
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

可参考如下demo:

@Entry  
@Component  
struct Index {  
  @State message: string = 'Hello World';  
  @State person:Person = new Person()  
  @Builder  
  itemView2(item: Person) {  
    RelativeContainer() {  
      Text(item.name)  
        .fontColor(Color.Black)  
        .fontSize(15)  
        .margin({ left: 10, top: 20 })  
        .id('id_name')  
      Text(item.sex)  
        .fontColor(Color.Gray)  
        .fontSize(13)  
        .alignRules({  
          top: { anchor: 'id_name', align: VerticalAlign.Bottom },  
        })  
        .margin({ left: 10, top: 5 })  
        .id('id_sex')  
      Text(item.phone)  
        .fontColor(Color.Red)  
        .fontSize(12)  
        .alignRules({  
          top: { anchor: 'id_name', align: VerticalAlign.Bottom },  
          left: { anchor: 'id_sex', align: HorizontalAlign.End }  
        })  
        .margin({ left: 5, top: 5 })  
        .id('id_phone')  
      Image($r('app.media.startIcon'))  
        .width(40)  
        .height(40)  
        .objectFit(ImageFit.Cover)  
        .alignRules({  
          left: { anchor: 'id_phone', align: HorizontalAlign.End },  
          center: { anchor: 'id_phone', align: VerticalAlign.Center },  
        })  
        .id('id_avatar')  
    }  
    .width("auto")  
    .height("auto")  
    .borderColor(Color.Pink)  
    .borderWidth(5)  
  }  
  build() {  
    Column() {  
    this.itemView2(this.person)  
    }  
    .justifyContent(FlexAlign.Center)  
    .height('100%')  
    .width('100%')  
  }  
}  
class Person {  
  name: string = "John"  
  sex: string = "男"  
  phone: string = "8208208820"  
  age: number = 18  
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
分享
微博
QQ
微信
回复
2024-10-15 17:58:44
相关问题
HarmonyOS相对布局问题
1011浏览 • 1回复 待解决
HarmonyOS 文字和图片相对布局问题
602浏览 • 1回复 待解决
相对布局(RelativeContainer)
2086浏览 • 1回复 待解决
HarmonyOS 列表高度不相同布局
728浏览 • 1回复 待解决
ets中设置布局高度和宽度
3800浏览 • 1回复 待解决
HarmonyOS 布局尺寸问题
813浏览 • 1回复 待解决
HarmonyOS 布局问题
681浏览 • 1回复 待解决
HarmonyOS scroll高度设置问题
2044浏览 • 1回复 待解决
HarmonyOS 高度自适应问题
1051浏览 • 1回复 待解决
HarmonyOS 弹窗高度问题
744浏览 • 1回复 待解决