kroegerama kroegerama - 1 month ago 18
Android Question

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?

Answer

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.

Comments