SwapsAgNO3
SwapsAgNO3

Reputation: 103

Android webview scaling issue

I have a Grid View in WebView(Android) and need to determine number of items that can be fit on the screen. I need this number to be sent to server to retrieve those many items from server. When I query the screen size in my Activity, it returns width : 800 and and height: 522(in landscape). But when the width is queried from javascript, the width returned is 1063. I have done appropriate settings for Viewport.

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

As both the values are different, it messes my calculations. The WebView display more items than my calculations per items.

Can someone please point out what am I messing up?

Thanks.

Upvotes: 2

Views: 2334

Answers (1)

Yashpal Singla
Yashpal Singla

Reputation: 1994

You need to map the webview with the screen layout by using setInitialScale over the webview.

Initial scale is defined in % so you need to specify something like below

int scalingFactor = ((float)800/(float)1063)*100

mPageWeb.setInitialScale(scalingFactor);

I hope this will solve your issue.

Upvotes: 2

Related Questions