Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • All images inside the drawable folder, with different names for each dimension
  • An xml file in each of this 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 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?

like image 852
IvanRF Avatar asked Feb 11 '13 15:02

IvanRF


People also ask

How would you support different screen sizes?

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.

How do I make my apps fit all screen sizes?

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.

How do I manage different screen size and orientation in Android?

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.


1 Answers

/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

like image 130
Karakuri Avatar answered Oct 12 '22 12:10

Karakuri