drawable 文件夹 - 我需要什么分辨率 [英] drawable folders - What resolutions do I need

查看:21
本文介绍了drawable 文件夹 - 我需要什么分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中使用的所有图像都位于一个文件夹中 -> drawable-hdpi.我将它们用作我的按钮、布局和一些图像视图的背景.这些图像具有从 50x50px 到 900x900px 的所有不同尺寸.

All images I use in my app are located in one folder -> drawable-hdpi. I use them as backgrounds for my buttons, for my layouts and for some imageViews. These images have all different sizes from 50x50px to 900x900px.

我根据屏幕大小(以像素为单位)计算按钮和其他控件的大小(以像素为单位).

I calculate the size of my buttons and other controls (in pixels) depending on the screen size (in pixels).

伪代码:

 screenWidth = getScreenWidthInPixels();
 screenHeight = getScreenHeightInPixels();

 myButtons.setHeight(screenHeight * 0.1); //buttonHeight = 10 % of screenHeight
 ......
 ...
 ..

我希望我的图像(按钮背景、图像视图、布局背景等)的质量在所有设备上都很好.现在有 5 个不同的可绘制文件夹.据我所知,我现在可以将 drawable-hdpi 文件夹中已有的相同图像放在其他四个可绘制文件夹中,但分辨率不同.我现在想弄清楚的是我必须为什么文件夹选择什么分辨率.就像我说的,我的图片现在的分辨率从 50x50 像素到 900x900 像素不等.

I want the quality of my images (button backgrounds, imageviews, layout backgrounds, ...) to be good on all devices. There are now 5 different drawable folders. As far as I know I can now put the same images I already have in my drawable-hdpi folder in the other four drawable folders but with different resolutions. What I'm trying to figuring out right now is what resolution I have to pick for what folder. And like I said, my images have resolutions right now from 50x50px to 900x900px.

推荐答案

这些是 dpi 中的分辨率:

These are the resolutions in dpi:

ldpi:    120 dpi  
mdpi:    160 dpi  
hdpi:    240 dpi  
xhdpi:   320 dpi  
xxhdpi:  480 dpi  
xxxhdpi: 640 dpi  

您必须根据结果以像素为单位计算尺寸:

You have to calculate the dimensions in pixels basing on the resulution:

比例因子:

ldpi:    0.75  
mdpi:    1.0  
hdpi:    1.5  
xhdpi:   2.0  
xxhdpi:  3.0  
xxxhdpi: 4.0

您可以将所有图像放在 xxxhdpi 文件夹中,然后让 Android 将它们缩小...但并非总是您会得到很好的结果(Android 缩放 DOWN 很好,但不如预大小的图像).
现在我想 xxhdpi 分辨率就足够了,但明天...
它会在 xxxhdpi 屏幕上向上缩放,结果不太好(可见像素化).

You COULD have all the images in the xxxhdpi folder and let Android scale them down... but not always you'd get nice results (Android scaling DOWN is good, but not as good as pre-sized images).
Nowadays I guess that an xxhdpi resolution is enough, but tomorrow...
It would be scaled UP on an xxxhdpi screen, with not-so-good results (visible pixellation).

一种解决方案是使用 svg 图形(这是一种基于 xml 的矢量标准),但是您需要一个外部库(有几个开源/免费的 - 您可以选择最适合的一个)来渲染它们标准控件.

A solution would be using svg graphics (which is a vectorial standard based on xml), but you'd need an external library (there are several open source / free - you choose the one which fits best) to render them in a standard control.

这篇关于drawable 文件夹 - 我需要什么分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆