简体   繁体   中英

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. Any help would be greatly appreciated.

You seem to think that 1dp equals 1px, which is not (always) correct.

It depends on the screen density (thats how many pixels are displayed per inch) how many pixels equal 1dp. The 1 to 1 conversion only applies at 160 dpi (mdpi in android terms) . 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. 1dp is smaller than 1px in this case, resulting in a smaller view.

See the dp description in the docs for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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