Android is not picking right dimens.xml file from values folder

Arif Nadeem picture Arif Nadeem · Apr 4, 2014 · Viewed 11.7k times · Source

I have created different dimens.xml files and placed them in appropriate values folder.

I have the following "value" folders defined

values, values-large, values-normal, values-small, values-sw320dp, values-sw320dp-land, values-sw480dp, values-sw600dp, values-sw720dp and values-sw720dp-land

The problem is when I install the app on phone <= 5 inches, dimens.xml from values-sw320dp is selected by Android. The selection is independent of screen density.

I have tested the app on S4, Moto G, S4 Mini and some 2.3 device. The results are the same throughout.

What am I doing wrong here?

Answer

Arif Nadeem picture Arif Nadeem · Apr 7, 2014

Well it is now clear to me that values-sw320dp will be the only folder from which dimens.xml will be picked as phones <= 5 inches fall into that category.

The mistake I was making was ignoring the screen density for 320dp size screens.

So the solution I found works is to create different value folders based on screen density i.e. create folders named values-sw320dp-ldpi, values-sw320dp-mdpi, values-sw320dp-hdpi, values-sw320dp-xhdpi and values-sw320dp-xxhdpi and put the corresponding dimens.xml files in them.

I hope this helps to people who might stumble upon this problem.