#鸿蒙通关秘籍#在HarmonyOS中如何设置图片缩放样式?

HarmonyOS
2024-12-04 14:11:18
840浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
SQL晨曦光

图片缩放样式通过 objectFit 属性设置。以下是几种常用样式的示例:

Image($r('app.media.img_2'))
  .width(200)
  .height(150)
  .objectFit(ImageFit.Contain)
  .overlay('Contain', { align: Alignment.Bottom, offset: { x: 0, y: 20 } })

Image($r('app.media.img_2'))
  .width(200)
  .height(150)
  .objectFit(ImageFit.Cover)
  .overlay('Cover', { align: Alignment.Bottom, offset: { x: 0, y: 20 } })

Image($r('app.media.img_2'))
  .width(200)
  .height(150)
  .objectFit(ImageFit.Fill)
  .overlay('Fill', { align: Alignment.Bottom, offset: { x: 0, y: 20 } })
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
分享
微博
QQ
微信
回复
2024-12-04 16:31:55


相关问题