This is because when you specify dimensions in Java, it is automatically treated as a pixel value.
You will need to implement a helper method somewhere, best of all in a helper class that calculates and returns a value independent of pixel density based on the provided pixel value.
The equation is px = dip * (density / 160) , from which we get that dip = px / (density/160) .
This answer here is actually even better.
source share