#鸿蒙通关秘籍#实现自适应缩放有什么方法?

HarmonyOS
2024-12-10 12:12:27
860浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
网络小英雄

可以使用layoutWeight属性来调整Row或Column容器子元素的主轴权重,或者直接使用百分比来设置宽度。

bash @Entry @Component struct layoutWeightExample { build() { Column() { Text('1:2:3').width('100%') Row() { Column() { Text('layoutWeight(1)') .textAlign(TextAlign.Center) }.layoutWeight(1).backgroundColor(0xF5DEB3).height('100%')

    Column() {
      Text('layoutWeight(2)')
        .textAlign(TextAlign.Center)
    }.layoutWeight(2).backgroundColor(0xD2B48C).height('100%')

    Column() {
      Text('layoutWeight(3)')
        .textAlign(TextAlign.Center)
    }.layoutWeight(3).backgroundColor(0xF5DEB3).height('100%')

  }.backgroundColor(0xffd306).height('30%')
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.

} }

@Entry @Component struct WidthExample { build() { Column() { Row() { Column() { Text('left width 20%') .textAlign(TextAlign.Center) }.width('20%').backgroundColor(0xF5DEB3).height('100%')

    Column() {
      Text('center width 50%')
        .textAlign(TextAlign.Center)
    }.width('50%').backgroundColor(0xD2B48C).height('100%')

    Column() {
      Text('right width 30%')
        .textAlign(TextAlign.Center)
    }.width('30%').backgroundColor(0xF5DEB3).height('100%')
  }.backgroundColor(0xffd306).height('30%')
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.

} }

分享
微博
QQ
微信
回复
2024-12-10 12:58:27
相关问题
自适应缩放布局如何实现
1305浏览 • 1回复 待解决
自适应页面滚动如何实现
1267浏览 • 1回复 待解决
Grid组件如何实现高度自适应
4143浏览 • 1回复 待解决
Web组件如何实现高度自适应
1734浏览 • 1回复 待解决
HarmonyOS 如何实现自适应web的高度
634浏览 • 1回复 待解决