我想在res / drawable文件夹中保留一个图像,该文件夹将用作我的应用程序中的背景。我希望我的应用程序可以在不同密度的所有设备上运行。应该保留图像的最小像素大小,以便在合理的应用程序大小和支持多个屏幕之间保持平衡。
开发者指南提到:
xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
我使用Photoshop,其中图像总是以像素为单位而不是dp,因此造成混乱。顺便说一下,我在Android和Photoshop上都很新。
答案 0 :(得分:2)
如果要将dp值转换为像素,可以使用以下公式:
int px =(int)(dp * logicalDensity + 0.5);
要从像素获取dp,请将密度除以像素值而不是乘以。
答案 1 :(得分:1)
尝试研究9-patch image。这张图片可以解决您的问题。
答案 2 :(得分:0)
您必须在drawable-mdpi文件夹中创建320x480尺寸的图像,并在drawable-hdpi文件夹中保存480x800尺寸
这两种尺寸的图像都可以在每个小型和大型屏幕设备中运行。
适用于中型设备320x480和高密度480x800。
答案 3 :(得分:0)
根本不要使用固定大小的图像。使用小图像作为平铺背景或将背景定义为渐变或使用xml资源的任何内容。
答案 4 :(得分:0)
px是一个像素。与尺度无关的像素(sp)和与密度无关的像素(dip),您希望将sp用于字体大小,并将其他所有内容用于倾斜。 dip == dp from http://developer.android.com/guide/topics/resources/more-resources.html#Dimension
px
Pixels - corresponds to actual pixels on the screen.
in
Inches - based on the physical size of the screen.
mm
Millimeters - based on the physical size of the screen.
pt
Points - 1/72 of an inch based on the physical size of the screen.
dp
Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".
sp
Scale-independent Pixels - this is like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.