dimen.xml is not being executed after specifying it for other sizes

237 views Asked by At

In my project I just had a dimens.xml file and after completing my project I decided to create dimens files for other screen sizes. So I began with creating values-mdpi directory and placing a dimen.xml file in it. but now every dimen resource I define in values-mdpi dimens file applies to all screens! In other word the general dimens file is being ignored. But if I define value-xxxhdpi an place the resources for my device in there is works fine. But why? If I don't define a dimens file for specific density it must take resources from general dimens.xml, must not?

2

There are 2 answers

0
TheWanderer On BEST ANSWER

Density-specific resources will match the lowest-matching type.

So, if you make a values-mdpi folder, any device that's MDPI or greater (most devices) will use any existing values in that folder, and fall back to the default otherwise.

Your values-xxxhdpi folder likely doesn't apply to your device because your device doesn't match the XXXHDPI spec. It might be XXHDPI or XHDPI.

You should switch your logic. Instead of creating special layouts for low-density devices, create special layouts for high density devices.

0
Rizwan Atta On

Please make a folder named as "values-nodpi" and put general in that it should work there ! this should help!

NOTE!:its better to do it this way though android does provide support for highdpi folders and also automatically regress it out for lower ones but it affects performance