adding image resources and using one as a layout background

4.6k views Asked by At

so im working on my first app and i have a question about images

first off, theres 4 different drawable folders, do i just drop an image into one of them? what is the proper way of adding a resource image?

secondly, i know theres a bunch of different resolutions for phones. should i just use one that is say, 960x720dp? or is there another appropriate way of doing this? i want to add an image as a resource into my project, then use it as the background for my app layout...

3

There are 3 answers

0
jeet On BEST ANSWER

You just need to paste your images into drawable folders. To address different resoulutions, you can place different images into different drawable folders with same name, say for logo.jpg into drawable-ldpi might have image logo.jpg with resolution fit to ldpi, and drawable-mdpi have image logo.jpg with resoluiion fit to mdpi. or if any image must be same for all resolutions then place a single image into any of the drawable folder.

0
Naresh Sharma On

You can do this by adding just one images in any folder but this link of supporting multiple screens and resolution of images provide you the best way to do that. Just read that

0
SynapseOne On

The best way is to put 4 different versions of the image in the 4 folders . The simplest way to find out what resolution each folder must have is to use mdpi image as a reference and multiply other 3 like this:

ldpi  = mdpi x 0.75
mdpi  = this is the reference resolution
hdpi  = mdpi x 1.5
xhdpi = mdpi x 2

Example: for an image that has 100 x 80 px as the base image, the other folder sould contain images with the following res:

ldpi  =  75 x  60 px
mdpi  = 100 x  80 px  this is the reference image
hdpi  = 150 x 120 px
hhdpi = 200 x 160 px

The best way is to create the biggest image in you image editor that you will need and make smaller variants from that. you can fint you own mathematical formula for the multiplication

If you don't want to put different variants for the image then let Android OS convert the images for you The Android OS will search the reference image in mdpi folder so make sure to put the image in this folder

More info here