Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android difference between 480x800 hdpi and 480x800 mdpi

Tags:

android

I am testing my app on the android emulator. On one screen I have a banner ad. The dimensions of the ad are 320x50.

When I start up an emulator of resolution 480x800 and 240dpi (hdpi), the banner ad is taking up the entire width of the screen.

When I start up an emulator with the same resolution but 160dpi (mdpi), the banner ad is taking up only a portion of the screen as I would expect (320 out of the 480 pixels are taken by the ad)

I'm having trouble understanding why a 480x800 device appears to have a 320dp screen width? With my understanding, displaying a 320px wide image on a 480px wide device should surely leave some space either side. I don't see how the dpi affects anything there, seeing as the resolutions are the same. I believe the higher dpi will just mean the physical device will have a smaller screen

like image 201
Roger Cuthbert Avatar asked Jan 18 '23 12:01

Roger Cuthbert


1 Answers

A 480x800 device at HDPI has a screen width of 320dp. As Google's docs say, "on a 240 dpi screen, 1 dp equals 1.5 physical pixels". So that means a resource specified as 320dp on an HDPI screen will display as 320*1.5=480 pixels.

In the case of mdpi (160dpi) I believe dp and px are 1:1, so a 320dp wide resource will display as 320*1=320 pixels. Note that it is pretty rare to have an mdpi device with 480px width, that'd be a pretty big and pixelated looking screen.

like image 163
Sam Dozor Avatar answered Jan 31 '23 02:01

Sam Dozor