0

I want to use background image in my app.But i am so confused about different screen sizes.I found this question:

Android: Background Image Size (in Pixel) which Support All Devices

But in answer he said xxxhdpi: 1280x1920 px but Lg G3 is xxxHdpi and screen resolution: 1440 x 2560

I need a roadmap.How should be my image sizes for all screens ? (mdpi,hdpi,xhdpi etc.)

Community
  • 1
  • 1
Okan
  • 1,379
  • 3
  • 25
  • 38

3 Answers3

3

Android devices' screen sizes in pixels and screen width in inches, can differ significantly from device to device. To address this issue, google lets you use different resources per size/density category See here for some more info.

Generally speaking, you must put the largest size image that you want to support for each dpi in the correct folder, and let android do the resizing.

You can also check the imageView's ScaleType attribute to choose how to scale the image to fit the view.

EDIT

the reason to use the different folders and not just one large image is that the larger the image, the more memory it consumes. For example a 1920x1280 image is nice to have on a 1920 screen, but on a 320pixels screen the extra resolution is wasted and you have a lot of wasted memory used.

Evripidis Drakos
  • 872
  • 1
  • 7
  • 15
  • If I put 1080p image to xxxhdpi folder what will happen on lg g3 ? it is 2k screen and using xxxhdpi. – Okan Jan 28 '15 at 13:58
  • android chooses which image to use based on the screen size. So in a xxxhdpi screen, it will try to find the image in the xxxhdpi foler. If it doesnt find it (you dont have an explicit image for this dpi) it will use a lower dpi image. In any case, after it gets the image it will try to fit it in the view you set it to. If for example, in the lg g3, your view takes up the whole screen, the image is lower res than the screen so it will scale up(depending on scaleType), loosing some quality, though I doubt it will be noticable. – Evripidis Drakos Jan 28 '15 at 14:09
  • hmmm ok,but i am still confused about sizes.I need example sizes for every screen xhdpi,xxhdpi etc. I am using this image with full screen – Okan Jan 28 '15 at 14:11
  • Read the first link I posted. In android you don't (and can't really) deal with absolute resolutions. Each screen can be different in resolution, dpi, aspect ratio etc. All you can do is a best effort approach where you set different images on each dpi folder size, orientation etc. You can use a drawable-swXXXdp to provide images based on smallest dimension of screen. Its all in the link I provided – Evripidis Drakos Jan 28 '15 at 14:21
2

An easier way is to include one single image in your drawable directory, then, in the OnCreate function of your activity, create a bitmap to fit the screen and put it in an imageview that has width and height set to "wrap_content".

This should work for any device.

vipluv
  • 607
  • 5
  • 8
0

Read this link. In particular, I think what you're looking for is:

To create alternative bitmap drawables for different densities, you should follow the 3:4:6:8:12:16 scaling ratio between the six generalized densities. For example, if you have a bitmap drawable that's 48x48 pixels for medium-density screens, all the different sizes should be:

36x36 (0.75x) for low-density

48x48 (1.0x baseline) for medium-density

72x72 (1.5x) for high-density

96x96 (2.0x) for extra-high-density

180x180 (3.0x) for extra-extra-high-density

192x192 (4.0x) for extra-extra-extra-high-density

and also:

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

nstosic
  • 2,584
  • 1
  • 17
  • 21
  • If you were creating background image,what sizes were you choose size for mdpi ? – Okan Jan 28 '15 at 13:37
  • That depends on your preference but I assume you can use YouTubes standard (480p i.e. 800x480 for middle range) – nstosic Jan 28 '15 at 13:39
  • If I choose 480x800 for mdpi,xxhdpi should be 1440x2400 right ? I think it is too big for xxhdpi ? – Okan Jan 28 '15 at 13:42
  • Well then you can use the lower boundaries for the screen sizes (i.e. 320 for normal, 480 for large, 720 for xlarge and 1080 for xxlarge) – nstosic Jan 28 '15 at 13:48