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

2

12

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?

Sepoy answered 4/4, 2014 at 9:46 Comment(3)
Please refer #16455251Faust
I am able to solve my problem by appending hdpi, xhdpi and xxhdpi to values-sw320dp. I created the following folders values-sw320dp-hdpi, values-sw320dp-xhdpi and values-sw320dp-xxhdpi and added the corresponding dimens.xml file. Now the correct dimensions are picked.Sepoy
Great :) Yes, qualifiers are required as mentioned in that SO post.Faust
D
3

I don't know what is the problem in the way you are trying. But I always create values folders like this values, values-ldpi, values-mdpi, values-hdpi, values-xhdpi, values-w360dp-mdpi, values-w600dp-mdpi and so on. Its always work for me.

Dyspnea answered 4/4, 2014 at 9:54 Comment(1)
The purpose of dp gets defeated by defining values folder with density qualifierTubb
S
10

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.

Sepoy answered 7/4, 2014 at 6:26 Comment(3)
This makes no sense. Screen sizes and screen resolutions are not the same. You can have a screen size smaller than 5 inches but a resolution that exceeds 320 dp.Grimace
@AndroidDev Please read my question again, I had asked "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 know for a fact that screen size and resolutions are not the same, yet in my case values-sw480dp configurations were ignored, the reason being that none of my phone had above xhdpi resolution, please see this (ldpi (low) ~120dpi mdpi (medium) ~160dpi hdpi (high) ~240dpi xhdpi (extra-high) ~320dpi) from developer.android.com/guide/practices/screens_support.htmlSepoy
But I guess that if you use any QHD phone of today you would have to use 480dp or 640dp configurations, you can future proof your app by doing this.Sepoy
D
3

I don't know what is the problem in the way you are trying. But I always create values folders like this values, values-ldpi, values-mdpi, values-hdpi, values-xhdpi, values-w360dp-mdpi, values-w600dp-mdpi and so on. Its always work for me.

Dyspnea answered 4/4, 2014 at 9:54 Comment(1)
The purpose of dp gets defeated by defining values folder with density qualifierTubb

© 2022 - 2024 — McMap. All rights reserved.