【问题标题】:How to manage/add multiple image resolution/size in flutter for responsive UI [closed]如何在响应式 UI 中管理/添加多个图像分辨率/尺寸 [关闭]
【发布时间】:2020-11-21 02:06:26
【问题描述】:
我有来自不同 dpi 数组的位图图像,如何正确排列它们? - 就像将它们放在 Android 上的 mipmaps 文件夹中一样。
Dpi 列表:
- ldpi - 0.75x
- mdpi - 1.0x
- hdpi - 1.5x
- xhdpi - 2.0x
- xxhdpi - 3.0x
- xxxhdpi - 4.0x
【问题讨论】:
标签:
flutter
flutter-layout
flutter-assetimage
【解决方案1】:
您需要做的是按照flutter pattern 安排您的图片资源
因此,如果您将 pubspec.yaml 上的图像路径设置为:
flutter:
assets:
- images/
您只需按以下方式排列文件:
-
images/0.75x/my_icon.png(0.75x 文件夹内的 ldpi)
-
images/my_icon.png(mdpi 直接在图片中)
-
images/1.5x/my_icon.png(1.5x 文件夹内的 hdpi)
-
images/2.0x/my_icon.png(2.0x 文件夹内的 xhdpi)
-
images/3.0x/my_icon.png(3.0x 文件夹内的 xxhdpi)
-
images/4.0x/my_icon.png(4.0x 文件夹内的 xxxhdpi)
并且当你使用Image.asset("images/my_image.png") 时,flutter 会自动分配正确的资产。