kroegerama
kroegerama

Reputation: 891

Android WebView zoom out after page is loaded

I have an initialized WebView with the following code:

_webView.setWebViewClient(new WebViewClient() {
   @Override
   public void onPageFinished(WebView view, String url) {
       while (view.zoomOut());
    }
_webView.loadURL("path/to/image.png");

But this does not work. The WebView zooms out while loading. But when it is finished, it will zoom in.

Is there any other way to zoom out completely after a page (I use the WebView to display an image) is loaded?

Upvotes: 1

Views: 8883

Answers (3)

Capt. Fuzzbucket
Capt. Fuzzbucket

Reputation: 11

These are the two most important commands when loading images:

webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);

Upvotes: 1

Yuvi
Yuvi

Reputation: 1350

Don't do anything in onPageFinished() instead use webview.getSettings().setDefaultZoom(WebviewSetting.ZoomDensity.FAR);

Hope this helps

Upvotes: 1

Ghost
Ghost

Reputation: 3966

Try this piece of code:

public class WebViewSampleActivity extends Activity 
{
     WebView wb;
    private class HelloWebViewClient extends WebViewClient 
    {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) 
        {
            return false;
        }
    }
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);      
        wb=(WebView)findViewById(R.id.webView1);        
        wb.getSettings().setJavaScriptEnabled(true);
        wb.getSettings().setLoadWithOverviewMode(true);
        wb.getSettings().setUseWideViewPort(true);
        wb.getSettings().setBuiltInZoomControls(true);
        wb.getSettings().setPluginState(WebSettings.PluginState.ON);
        wb.getSettings().setPluginsEnabled(true);           
        wb.setWebViewClient(new HelloWebViewClient());
        wb.loadUrl("http://www.foofoo.com");        
    }
}

Hope this helps.

Upvotes: 8

Related Questions