Supports all screen sizes and Android versions
I am developing an Android application and I want to use images as background for actions. I am targeting from API 8 to latest. I would like to know what is the best way to do it.
I have read Support for Multiple Screen Sizes and Support for Multiple Screens .
So, I made 4 images for each background with the following dimensions: 320x480, 480x800, 600x1024, 800x1280. First, I put the files in these folders respectively drawable-sw320dp, drawable-sw480dp, drawable-sw600dp, drawable-sw720dp
. Then I realized that this only works for Android 3.2 and up, so I needed to add small, regular, large and xlarge folders. In order not to duplicate files, I followed the ideas in this section of the first article .
Final structure:
- All images inside a folder
drawable
with different names for each dimension - xml file in each of these folders:
values-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
- And
drawables.xml
in the eight folders mentioned above.
Content drawables.xml
for folders values-sw480dp
and values-normal
:
<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 works fine. However, I get this Lint warning for each image: "Found bitmap drawable res / drawable / bg_main_480.png in density folder. Problem: Ensures images are not defined in density independent portable folder." I know what this means, but I will not continue to create more images for each dp as it is pointless.
Is the structure I am using correctly? what do you suggest?
source to share
/res/drawable
Should not have any image files, it should only include drawings defined using XML. You must place your actual image files in qualified drawable directories based on the target pixel density. If you don't want to specify any classifier, put them in
/res/drawable-nodpi
source to share