Why does a 600dp wide view take up my entire landscape width of the Nexus 5?

I specify the button width as 600dp in values/dimens.xml, but when I deploy and run it on my Nexus 5, it takes up all the available width in landscape orientation.

My activity only works in landscape mode, as I indicated in the manifest file. Layouts are in the catalog layouts. The images are in the "drawable-xxhdpi" directory and they look great, but everything I point to dpis enlarged.

The preview in Android Studio and the actual device seem to behave the way they have a maximum width of 600dp when it should be 1920. Why is this and how can I fix it?

+4
source share
1 answer

The physical width of the display on the Nexus 5 terrain is 1920 pixels, but 600dp! = 600 pixels. Nexus 5 has a display density of ~ 445 dpi. Dp are pixels only at medium density (160 ppi). Thus, everything that is specified in dp will scale at approximately 445/160 = 2.78125. So 600dp is actually about 1669 pixels. This should account for most of what you see.

There might also be something regarding your layout that stretches the button. If you post your xml layout, we can provide additional information.

+6
source

All Articles