2

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I had already set Webview.setInitialScale(100); I need to know why I get 1063. This value is returned for a particular device. I am sure other devices might return other values. Hence I cannot use the solution you have mentioned. I need to know the reason why I receive that value, so that I can formulate a solution for all devices.
Not to 100 to int scalingFactor = ((float)800/(float)1063)*100
The point that I am trying to make is I cannot use 1063. This value appears for only one device i.e. for a tablet. If I use a 240*320 device this value will change and the scaling factor calculated using your approach will be wrong for it. Hence I need the reason for this value occurring.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.