Reputation: 1119
I want to keep an image in the res/drawable folder, which would be used as the background in my app. I wish that my app should work across all devices of varying densities. What minimum size in pixels should the image be kept to maintain balance between a reasonable app size and also supporting multiple screens.
The developer guide mentions that:
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
I use Photoshop where the images are always in pixels and not dp and hence the confusion. By the way, I am quite new at Android as well as Photoshop.
Upvotes: 0
Views: 3007
Reputation: 3001
px is one pixel. scale-independent pixels ( sp ) and density-independent pixels ( dip ) you want to use sp for font sizes and dip for everything else. dip==dp from here 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.
Upvotes: 0
Reputation: 2086
If you want to convert dp values to pixels u can use following formula:
int px = (int) (dp * logicalDensity + 0.5);
To get dp from pixels, divide the density into the pixel value rather than multiply.
Upvotes: 2
Reputation: 1489
Try to study about 9-patch image. This single image could solve your issue.
Upvotes: 1
Reputation: 29912
Don't use a fixed size image at all. Use a little image as a tiled background or define background as a gradient or whatever using xml resources.
Upvotes: 0
Reputation: 1372
You have to create images 320x480 size save in drawable-mdpi folder and 480x800 size save in drawable-hdpi folder
These both size image run in every small and large screen device.
for medium device 320x480 and for high density 480x800.
Upvotes: 0