简体   繁体   English

适用于不同屏幕的Android图像

[英]Android images for different screens

I'm developing an Android app which uses a number of images and icons. 我正在开发一个使用许多图像和图标的Android应用程序。 In order to prevent the device to work hard and run out of memory, I want to create multiple images for each screen size. 为了防止设备辛苦工作并耗尽内存,我想为每个屏幕尺寸创建多个图像。
My question is: Do I need to measure exactly what dp I want and then convert it to pixels? 我的问题是:是否需要精确测量我想要的dp,然后将其转换为像素?
Sometimes it's hard to know exactly the size of the image in dp- for instance if it's width is match_parent and there's margin etc. 有时很难确切地知道dp中图像的大小,例如,图像的宽度是否为match_parent且有边距等。

How can I solve this problem? 我怎么解决这个问题?
I would be glad for guidance on how to do this the best way. 我很乐意为您提供最佳方法指导。

Do not create images for each screen size , but rather for each screen density . 不要为每个屏幕尺寸都创建图像,而是为每个屏幕密度 创建图像。 So you will need five different files for mdpi, hdpi, xhdpi, xxhdpi and xxxhdpi (if you don't want to support some of these, just don't put the file in the corresponding folder). 因此,对于mdpi,hdpi,xhdpi,xxhdpi和xxxhdpi,您将需要五个不同的文件(如果您不想支持其中一些文件,只需将文件放在相应的文件夹中)。 The algorithm is the following: take your image and put it to the 'xxxhdpi' folder. 算法如下:获取您的图像并将其放入“ xxxhdpi”文件夹。 Then resize it, so it looks as you want on a device with the xxxhdpi density screen. 然后调整它的大小,使其在具有xxxhdpi密度屏幕的设备上看起来像您想要的。 Then resize your image for other densities using the following ratios: 然后使用以下比率为其他浓度调整图像大小:

mdpi | hdpi | xhdpi | xxhdpi | xxxhdpi
1    | 1.5  | 2     | 3      | 4

For example, to get the size of your mdpi image, divide a width and a height of the xxxhdpi image by four. 例如,要获取mdpi图像的大小,请将xxxhdpi图像的宽度和高度除以四。

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

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