Mix-in Pixel for Android

Mudit Sen
2 min readAug 8, 2022

--

When Android platform launched, instead of pixel like in HTML+CSS, it came with something called Density Pixel to define dimensions of views like width, height, padding, margin etc.

Density pixel is amazing as it adjusts your view respective of the number of pixel per inch (pixel/inch). As android os wanted to support as many device as possible they came with this approach.
But this density pixel came with its fair share of problems. Like you may end up seeing different UI in different devices.
350dp maybe looks good in one device but overflows in another device or looks quite small in another device.

To solve this problem people have came up with many solutions and one of the solution is I am mentioning here which many Game Engines or Game Developers use.

Scale our views to a specified guideline dimension in our design system. This will definitely increase your code of managing views. But in long run your views will look good and pixel perfect. With Jetpack Compose instead of using “.dp” you can begin using mp(Mixin pixel) which we are about to define now.

I have used the above class in various projects and it works great in Portrait Applications.

One of the application where I am using Mix-in Pixel is Cryptogram which is available on PlayStore.

Download Cryptogram Game:

--

--