Setting Android webview initialScale prevents proper zooming

Posted by Ryan on Stack Overflow See other posts from Stack Overflow or by Ryan
Published on 2012-11-22T16:57:59Z Indexed on 2012/11/22 16:59 UTC
Read the original article Hit count: 165

Filed under:

Need:

I want a webview to automatically be sized to fit the width of that particular page. I have Googled this and found several different suggestions. Most of them work. But then each of them effects zooming in / zooming out.

What I'm looking for is a solution that accomplishes both. The webview is initially set to fill the screen, but then it allows the user to zoom in (with pinching) and zoom out.

What I've Tried:

mainView.getSettings().setLoadWithOverviewMode(true);
mainView.getSettings().setUseWideViewPort(false);
mainView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);  
mainView.getSettings().setBuiltInZoomControls(true);
mainView.getSettings().setSupportZoom(true);

I have also tried setting mainView.setInitialScale(various percentages)

Again, I have tried these in different orders, including some, not including others. Currently, if I use the above code and setInitialScale(65), it loads initially fine but then once you zoom in, you cannot zoom all the way back out.

Does anyone know of the best practice to set initial scale to fit screen but fully allow zooming out and in?

Why I Need It:

I'm using a ViewFlipper in my Android app to load several webviews simultaneously. I have a touch sensor that allows sliding from left to right to switch between different webviews. The practical purpose of this is to show a grocery store's ads and allow the user to slide from page to page.

The problem is that the API feed I'm using basically only allows me to load a URL for each page. So I have to use webviews.

© Stack Overflow or respective owner

Related posts about android