1

我正在使用图像说 85x85 像素(将此图像放入 drawable-mdpi 中)

如果我在 [320x480]mdpi 屏幕尺寸设备上显示此 85x85 像素的图像,它看起来不错,但在 [480x800]mdpi 设备上显示此图像时,它看起来非常小。

我想知道如何调整此图像的大小(85x85 像素),使其适用于屏幕宽度和高度为 480x800、mdpi 的设备。

4

4 回答 4

2

您必须在 dp.xml 中设置图像大小。这个帖子真的很有帮助。

于 2013-08-06T14:26:36.273 回答
1

考虑 MDPI 图像(比如说 85x85)作为基线 创建图像如下

文件夹 图像大小 百分比

LDPI 64x64 基线的 75%

MDPI 85x85 100% 基线

HDPI 127x127 基线的 150%

XHDPI 170x170 基线的 200%

于 2013-08-06T14:41:31.710 回答
0

The better solution for this is to produce LDPI,MDPI,HDPI,XHDPI,XXHDPI sized images and place it inside the corresponding folders.

于 2013-08-06T14:48:06.210 回答
0

Put the image in /drawable, and define the size of the image in your XML as 85dp, it will then be scaled for LDPI/HDPI/XHDPI/XXHDPI and god forbid XXXHDPI.

However, the better solution would to produce HDPI(128px)/XHDPI(170px)/XXHDPI(255px) version of the graphics and put them in /drawable-hdpi, /drawable-xhdpi, /drawable-xxhdpi respectively. This way you can provide the best experience for your users.


[Edit]

"dp" is Android's way of defining physical size of an UI objects, so a button of 48x48dp will have roughly the same physical dimension even when run on screen sizes between 240x320 to 1080x1920, for more information check Android developer site's Supporting Multiple Screens.

[Edit 2]

For images on canvas you can use this to calculate the scaled size of the image:

DisplayMetrics dm = new DisplayMetrics();
context.getWindowManager().getDefaultDisplay().getMetrics(dm);
int newSize = (int)(85 * (dm.densityDpi / 160f));
于 2013-08-06T14:31:39.183 回答