Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 806
Arif Nadeem Avatar asked Apr 04 '14 09:04

Arif Nadeem


People also ask

Where is dimens xml in Android Studio?

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.

What is dimens xml?

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.

Where is values xml file in Android Studio?

Deciphering the Styles file Fire up Android Studio and search for values. xml and select the one contained inside the appcompat-support library.


1 Answers

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.

like image 58
Arif Nadeem Avatar answered Oct 31 '22 13:10

Arif Nadeem