Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why android browser viewport is much smaller than actual screen size of the mobile phone, even when using width=device-width?

I would like to ask why my HTC Desire HD's browser reports viewport's width of 369px even though the actual pixel size of the screen is 480x800 WVGA.

I am using in my page this CSS styles:

<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0" />

Can you please explain me this strange behaviour and how to force Android browser to actually set viewport's width to 480px rather than weird 369px ?

Thank you for any help.

like image 930
Frodik Avatar asked Jan 17 '12 14:01

Frodik


People also ask

What is viewport size of device?

However device actual dimensions depends on actual Pixels Per Inch which is called "Viewport Size" of device or "device-width". Responsive Websites CSS styles are based upon Viewport sizes of devices. Below is a detailed comparison list of Viewport Size for devices, Phone Dimensions, Screen Sizes and Devices Resolution:

How to get the viewable height of the viewport on mobile?

The second way is to use window.innerHeight for your target element, as on mobile, it will always give you the viewable height of the viewport, but again, this again creates a problem as you will have to write this tiny JS for each of your use cases. So can there be an easy solution, which can give you the best of both worlds?

Which browsers support viewport units?

With newer viewport units, first support came in 2013 with FF and Chrome being the first ones quickly followed by Safari and Opera. (yes, IE used to suck even in those days). Now with newer viewport units and a ton on mobile devices, the browser communities don’t seem to agree on how to implement them in mobile devices.

What is the actual device dimensions of a website?

However device actual dimensions depends on actual Pixels Per Inch which is called "Viewport Size" of device or "device-width". Responsive Websites CSS styles are based upon Viewport sizes of devices.


1 Answers

A detailed explanation of the issue can be found in that blog post.

The number that you see (369px) is actually the size of the device multiplied by the default, assumed, screen density of 160 dpi.

In order to use the device screen density, you have to specify, in the viewport meta, that you want to use the device's dpi.

e.g.:

<meta name="viewport" content="width=device-width, target-densityDpi=device-dpi">

EDIT: The documentation of the WebView class now also has information about the target-densityDpi parameter, and the possible values.

like image 72
Jean Hominal Avatar answered Oct 01 '22 19:10

Jean Hominal