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?
res/sw600dp/layout. xml -> will be used for all screen sizes bigger or equal to 600dp. This does not take the device orientation into account. 2) Available Screen Width - Specifies a minimum available width in dp units at which the resources should be used.
Simple, use relative layout with the set margin code. Set the margins between each text view, button, etc and it will look the same on every phone. android:layout_marginTop="10dp" // change Top to Bottom, Left or Right for what you need.
Use “wrap_content” and “match_parent” To ensure that your layout is flexible and adapts to different screen sizes, you should use "wrap_content" and "match_parent" for the width and height of some view components.
/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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With