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?
xml is not created in the project by default. If you need a dimens. xml , you can just create one under the res/values folder with New -> Values resource file . true but there what is the cause of it and how to get it created automatically when the project is created.
Dimension. XML resource that carries a dimension value (with a unit of measure). ID. XML resource that provides a unique identifier for application resources and components.
Deciphering the Styles file Fire up Android Studio and search for values. xml and select the one contained inside the appcompat-support library.
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.
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