[英]Why does 1dp mean 3px and 2px at the same time on Android?
I use the following style for GridView
: 我对
GridView
使用以下样式:
<style name="CaldroidDefaultGridView">
<item name="android:adjustViewBounds">true</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:listSelector">@null</item>
<item name="android:background">@color/caldroid_lighter_gray</item>
<item name="android:horizontalSpacing">1dp</item>
<item name="android:padding">1dp</item>
<item name="android:verticalSpacing">1dp</item>
And it shows 3px for padding and 2px for spacing on Pixel 2 emulator. 并且在Pixel 2模拟器上显示3px用于填充,2px用于间隔。 If I implicitly specify 2px both for padding and spacing, then it shows 2px - so there is no extra pixel anywhere.
如果我隐式地指定2px用于填充和间距,那么它将显示2px-因此在任何地方都没有多余的像素。
It happens in both directions - horizontal and vertical. 它发生在水平和垂直两个方向。 For padding 1dp always means 3px.
对于填充1dp始终表示3px。 For spacing 1dp always means 2px.
对于间距1dp始终表示2px。
Why does 1dp mean 3px and 2px at the same time on Android? 为什么1dp在Android上同时表示3px和2px? How can I get the actual values then?
那我怎么得到实际值呢? Because I need to know them.
因为我需要了解他们。
PS I understand that it's hard to believe in the stated facts, so I can provide screenshots as the proof. 附言:我知道很难相信所陈述的事实,因此我可以提供屏幕截图作为证明。
dp means density-independent pixels. dp表示与密度无关的像素。 Every smartphone has a different number that goes around 300dp - 420dpi if I don't remember bad.
每个智能手机都有一个不同的数字,大约300dp-420dpi(如果我不记得不好的话)。 Anyway, your smartphone should have 1920x1080 as screen.
无论如何,您的智能手机的屏幕应该为1920x1080。 So that's because 1dp could be 2-3px at the same time.
这是因为1dp可能同时为2-3px。
You can read more in the official developer android website. 您可以在Android开发者官方网站上阅读更多内容。
https://developer.android.com/training/multiscreen/screendensities https://developer.android.com/training/multiscreen/screendensities
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.