Search code examples
androidxmlgraphicsscaling

Android scaling: dp units do not seem to work properly


So i wrote a bunch of code in xml for my app, started trying it on different devices and encountered a problem: although i was using only dp units (and sp for text), the visual output on the emulators with different screen sizes and densities varies a lot.

For example, I get proper output on one screen, and completely different one (very zoomed) on screen with similar size but higher density. I thought that using dp units is supposed to control for differences in screen densities, but it is not happening. Am I missing something?

One solution that i'm thinking of is making different "dimens.xml" files applying different qualifiers for both size and density. But after few hours of research I only realized that using density qualifiers for layout files (dimens.xml is considered to be one of them?) is not considered to be good practice. Moreover, even if i do this, i guess i will end up with a couple dozens different "dimens.xml" files, which is not good.

So, my question is how should I approach solving this scaling problem? Thanks.

PS. I've been developing for android for about a month now, so excuse me if i'm missing something trivial :)


Solution

  • Try using this library Intuit/sdp. It provides a new unit, sdp or scalable dp. It scales your size with the screen size and is very easy to use. This should solve your problem.