views:

107

answers:

1

Hi All,

I have tried the following to fit the webpage based on the device screen size.

      mWebview.setInitialScale(30);

and then set the metadata viewport

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

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

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

But nothing works, webpage is not fixed to the device screen size.

Can anyone tel me how to get this.

A: 

You have to calculate the scale that you need to use manually, rather than setting to 30.

private int getScale(){
    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); 
    int width = display.getWidth(); 
    Double val = new Double(width)/new Double(PIC_WIDTH);
    val = val * 100d;
    return val.intValue();
}

Then use

WebView web = new WebView(this);
web.setPadding(0, 0, 0, 0);
web.setInitialScale(getScale());
danh32
Thanks for your reply, u r right, it works. but I have different issue. I am not loading an image, loading the webpage in the webview, So how to find out the webpage width (PIC_WIDTH).
SWDeveloper
Ah, I missed that constant in there. Sorry about that. I am not sure how you can get the width of the actual webpage.
danh32