IvanRF
IvanRF

Reputation: 7255

Support all screen sizes and android versions

I'm developing an Android application and I want to use images as backgrounds for the activities. I'm targeting from API 8 to the latest. I would like to know what is the best way to do this.

I've read Supporting Different Screen Sizes and Supporting Multiple Screens.

So, I made 4 images for each background with this dimensions: 320x480, 480x800, 600x1024, 800x1280. First, I put the files in this folders respectively: drawable-sw320dp, drawable-sw480dp, drawable-sw600dp, drawable-sw720dp. Then, I realized that this only works for Android 3.2 and above, so I needed to add the small, normal, large and xlarge folders. In order not to duplicate files, I followed the ideas of this section of the first article.

The final structure is:

For example, for the background of the main activity I have:

The content of drawables.xml for the values-sw480dp and values-normal folders is:

<resources>
    <item name="bg_main" type="drawable">@drawable/bg_main_480</item> 
</resources>

I tested this in Android 2.3.7 and 4.0.3 and it is working fine. However, I'm getting this Lint warning for every image: "Found bitmap drawable res/drawable/bg_main_480.png in densityless folder. Issue: Ensures that images are not defined in the density-independent drawable folder". I know what it means, but I will not continue creating more images for each dp since it is pointless.

Is the structure I'm using right? what do you suggest?

Upvotes: 7

Views: 7343

Answers (2)

whiteLT
whiteLT

Reputation: 338

You can find valuable information here info

and also in "res" forlder you can see different drawables: 36x36 for low-density

48x48 for medium-density

72x72 for high-density

96x96 for extra high-density

you can put your files for particular resolution.

Upvotes: 0

Karakuri
Karakuri

Reputation: 38585

/res/drawable should not have any image files, it should only include drawables defined using XML. You should place your actual image files in qualified drawable directories based on the target pixel-density. If you don't want to specify any qualifier, place them in /res/drawable-nodpi

Upvotes: 17

Related Questions