androidscreen-density

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


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?


Solution

  • 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.