Reputation: 7255
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:
drawable
folder, with different names for each dimensionvalues-sw320dp, values-sw480dp, values-sw600dp, values-sw720dp, values-small, values-normal, values-large, values-xlarge
For example, for the background of the main activity I have:
drawable\bg_main_320.png
drawable\bg_main_480.png
drawable\bg_main_600.png
drawable\bg_main_720.png
drawables.xml
in the eight folders named above.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
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
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