简体   繁体   English

为什么我的android图形布局编辑器的eclipse dp尺寸不正确?

[英]Why are my eclipse dp dimensions for the android graphical layout editor not accurate?

While trying to make a layout for my app, I noticed that while using the QVGA skin(240 by 320) I noticed a button 240dp by 160 dp does not fill half of the screen vertically, nor the entire screen horizontally. 在尝试为我的应用程序进行布局时,我注意到在使用QVGA外观(240 x 320)时,我注意到240dp x 160 dp的按钮不能垂直填充屏幕的一半,也不可以水平填充整个屏幕。 Any help would be greatly appreciated. 任何帮助将不胜感激。

You seem to think that 1dp equals 1px, which is not (always) correct. 您似乎认为1dp等于1px,这(总是)不正确。

It depends on the screen density (thats how many pixels are displayed per inch) how many pixels equal 1dp. 它取决于屏幕密度(即每英寸显示多少个像素 ,多少个像素等于1dp。 The 1 to 1 conversion only applies at 160 dpi (mdpi in android terms) . 1对1转换仅适用于160 dpi (android中为mdpi) If you have a QVGA display created in the emulator/eclipse, chances are that it's density is 120 aka ldpi (by default) , so you get other dimensions. 如果您在模拟器/日食中创建了QVGA显示,则其密度很可能是120 aka ldpi (默认情况下) ,因此可以得到其他尺寸。 1dp is smaller than 1px in this case, resulting in a smaller view. 在这种情况下,1dp小于1px,因此视图较小。

See the dp description in the docs for more information. 有关更多信息,请参见文档中dp描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM