在Android的小数设置DP [英] Setting dp in decimals in Android

查看:1560
本文介绍了在Android的小数设置DP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置在Android的2个元素之间的距离。我已经设置了保证金1DP,我在想,距离比我想这是更多的。我认为0.5dp会就好了。是否有可能设置小数保证金为我想?如果是这样,什么是支持的最低DP?

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?

推荐答案

是的,你可以使用0.5dp或者你想永远十进制数,但要小心。当你的DP转换为像素他们乘显示逻辑密度和围捕。

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.

如果您的DP = 0.1比显示HDPI你(INT)(0.1 * 1.5 + 0.5)= 1像素。 (1.5是华电国际的显示逻辑密度)

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)

如果您的DP = 0.5,对于MDPI显示你(INT)(0.5 * 1 + 0.5)= 1像素的(1是适用于mdpi显示逻辑密度)

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)

这篇关于在Android的小数设置DP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆