Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Webview scalesPageToFit not working (Android)

var webview = Titanium.UI.createWebView({
    url:'index.htm',
    scalesPageToFit:true,
    contentWidth:'auto',
    contentHeight:'auto'
});

var window = Titanium.UI.createWindow();
window.add(webview);
window.open({modal:true});

My index.htm page (or any other URL I try) loads at fullres and absolutely refuses to fit the screen onLoad. I am extremely confused and cannot find anyone experiencing this issue. I have also tried adding this meta tag:

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

…but still the same results. From what I have read online and in other forums this is exactly the code that is used to scale the page to the screen, but for whatever reason it simply wont work.

Has anyone else experienced this? Am I missing some crucial snippet of code somewhere to get this working? So confused…

— asked April 26th 2011 by Luke Hurd
  • android
  • mobile
  • scalespagetofit
  • webview
0 Comments

7 Answers

  • i have solution Prevent zoom and still fit in screen .

    1 - set your html cod in div .

    2- set style for this div and set zoom 50% .

    '<div style="font-size: 25pt; zoom: 50%; " >' + your html code + '</div>';
    

    3 - put meta tag in head ( before div ).

    <meta name = "viewport" content = "user-scalable = no">
    

    4 - set scalesPageToFit:true, .

    This works fine for me on Android.

    I hope to be helpful to you .

    — answered January 21st 2013 by dab mh
    permalink
    1 Comment
    • This works for me on Android! Thanks a lot!

      — commented June 16th 2013 by Mason Zhang
  • hey Luke, I'm experiencing the same issue. Its hard trying to find help here.

    — answered May 5th 2011 by David Craigster
    permalink
    0 Comments
  • scalesPageToFit is not supported on Android at this time. I'm looking for a workaround as well and will post here if I find one.

    — answered May 12th 2011 by brian kurzius
    permalink
    1 Comment
    • This appears to have been fixed in 1.7: http://jira.appcelerator.org/browse/TIMOB-1540

      — commented May 12th 2011 by brian kurzius
  • I just confirmed that it is fixed in the latest build of 1.7: http://builds.appcelerator.com.s3.amazonaws.com/index.html – choose the master branch from the dropdown and download the latest 1.7 sdk.

    — answered May 12th 2011 by brian kurzius
    permalink
    3 Comments
    • are you sure it works in the latest build ?

      — commented November 16th 2011 by Eni Sinanaj
    • I'm not sure – I haven't been working with Titanium for the past few months and don't have time to test it right now. Good luck!

      — commented November 16th 2011 by brian kurzius
    • thanks for the fast answer mate :)

      — commented November 16th 2011 by Eni Sinanaj
  • I created a work around. Put the following line in your "load" event listener of webView. Let me know if this works or not.

    webView.evalJS("var m=document.createElement(\"meta\");m.name = \"viewport\";m.content = \"width=320, initial-scale=1, maximum-scale=1, minimum-scale=1\";document.getElementsByTagName(\"head\")[0].appendChild(m);");
    
    — answered February 14th 2012 by Jack Lin
    permalink
    0 Comments
  • I have created a web view like:

    var webView = Ti.UI.createWebView({
    url : 'listing.html'
    });
    and in my listing.html i have simply put this
    <head>
    <meta name = "viewport" content = "user-scalable = no"> </head>
    and it is working fine for me!!!!

    — answered March 29th 2012 by Parul Gupta
    permalink
    0 Comments
  • This works fine for me on Android.

            webview = Ti.UI.createWebView({
                height:Ti.UI.SIZE,
                width:Ti.UI.SIZE  ...
    

    So I went with the ugly if else.. hope it helps someone

    
            if (isAndroid) {
                  webview4 = Ti.UI.createWebView({ height:Ti.UI.SIZE, width:Ti.UI.SIZE});
            } else {
                webview4 = Ti.UI.createWebView({
                    scalesPageToFit:true
                    contentWidth:'auto',
                    contentHeight:'auto',
                });            
            }
    
    — answered January 20th 2013 by Jason Gomes
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.