简体   繁体   English

各种屏幕密度/尺寸的图像尺寸:最佳做法

[英]Image sizes for various screen density/sizes : best practice

I'm almost at the end of the dev of an app, and for now, I've put every image I use (whether it's icons, buttons, or photos) in 4 sizes. 我几乎快要开发一个应用程序了,现在,我已经将使用的每张图像(无论是图标,按钮还是照片)都分成4种尺寸。

For example let's say I've got a photo that I want to be 300x120dp, I've put: 例如,假设我有一张要设为300x120dp的照片,我把:

  • the photo with a 300x120px resolution in drawable-mdpi 在drawable-mdpi中具有300x120px分辨率的照片
  • the photo with a 450x180px resolution in drawable-hdpi 在drawable-hdpi中具有450x180px分辨率的照片
  • the photo with a 600x240px resolution in drawable-xdpi 在drawable-xdpi中具有600x240px分辨率的照片
  • the photo with a 900x360px resolution in drawable-xxdpi 在drawable-xxdpi中具有900x360px分辨率的照片

First question: is it the best practice? 第一个问题:这是最佳做法吗? Even for rather large photos? 即使是较大的照片? Just to be sure I understand: why can't we put a 900x360px photo in drawable folder and set the size in dp in the layout so that the image is scaled down on small screen densities? 为了确保我理解:为什么我们不能将900x360px的照片放在可绘制的文件夹中,并在布局中的dp中设置大小,以便在小屏幕密度下按比例缩小图像? For memory optimization? 为了进行内存优化?

Most importantly, I'm now working on layouts for 7 inches and 10 inches tablets. 最重要的是,我现在正在为7英寸和10英寸平板电脑进行布局。 Let's take the same image of 300x120dp. 让我们拍摄300x120dp的相同图片。 This image is too small for a 10 inches tablet, and so I would like it to be 600x240dp on that screen size. 对于10英寸的平板电脑,此图像太小,因此我希望在该屏幕尺寸上为600x240dp。 What must I do? 我必须做什么? Generate 4 new images? 生成4张新图片? If yes, let's say all my images are 2 times larger on a 10 inches tablet, must I generate 4 new images for all the images? 如果是,假设我的所有图像在10英寸平板电脑上都大2倍,我是否必须为所有图像生成4张新图像? And 4 new images for the 7 inches layouts? 还有7英寸布局的4张新图像?

Many thanks for your advices. 非常感谢您的建议。

If you have a photo (just photo, not graphic with sharp edges like icons and so on!) -- practically there is no need to make it for xxhdpi, or even xhdpi, pixels there are not recognizable by eye. 如果您有一张照片(只是照片,而不是带有图标之类的尖锐边缘的图形!)-几乎不需要为xxhdpi甚至xhdpi进行制作,则肉眼无法识别像素。 And make devices with medium resolution downsample hi-res pictures is bad practice, because often such devices have memory limits. 使具有中等分辨率下采样高分辨率图片的设备是不明智的做法,因为此类设备通常具有内存限制。 Remember that image in mdpi is 4 times lighter than xhdpi and 9 times lighter than xxhdpi. 请记住,以mdpi为单位的图像比xhdpi亮4倍,比xxhdpi亮9倍。

So, for photos (not icons and ui elements!): mdpi, hdpi, both for phones and tablets, will be enough. 因此,对于照片(不是图标和ui元素!):手机和平板电脑的mdpi,hdpi都足够。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM