I am trying to set the distance between 2 elements in Android. The margin I have set is 1dp and I was thinking that the distance is more than what I wanted it to be. I thought that 0.5dp would be just fine. Is it possible to set the margin in decimals as I am trying? If so, what is the minimum dp that is supported?
Yeah, you can use 0.5dp or what ever decimal number you want, but be careful. When your dp converted to pixels they multiplied by display logic density and rounded up.
You can use String. format("%. 2f", d) , your double will be rounded automatically. Save this answer.
Yeah, you can use 0.5dp or what ever decimal number you want, but be careful. When your dp converted to pixels they multiplied by display logic density and rounded up.
If your dp = 0.1 than for hdpi display you get (int)(0.1 * 1.5 + 0.5) = 1px. (1.5 is logical density for hdpi display)
If your dp = 0.5 that for mdpi display you get (int)(0.5 * 1 + 0.5) = 1px (1 is logical density for mdpi display)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With