Android WebView se aleja después de cargar la página

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?

preguntado el 02 de febrero de 12 a las 10:02

3 Respuestas

Prueba este fragmento de código:

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");        
    }
}

Espero que esto ayude.

Respondido 02 Feb 12, 14:02

Gracias, wb.getSettings().setLoadWithOverviewMode(true); me hizo el truco: D - kroegerama

You're welcome. It sure does, but you might also want to include wb.getSettings().setUseWideViewPort(true) along with it for better results. Anyway, I've included all essential settings in my code. Didn't want it to fail somewhere. :) BTW, thanks for accepting the answer :) - Fantasma

Yo uso .setUseWideViewPort(true) already. And now also the following ones: .setDefaultZoom(ZoomDensity.FAR); .setBuiltInZoomControls(true); .setLoadWithOverviewMode(true); These should provide the best results for my purpose. Thanks again =) - kroegerama

If I want the page loaded fit the screen width,but after that,if user want to zoom in the content it's too small to see it clearly.How we can free the Webview to do that? - Chine Gary

Don't do anything in onPageFinished() en su lugar usa webview.getSettings().setDefaultZoom(WebviewSetting.ZoomDensity.FAR);

Espero que esto ayude

Respondido 02 Feb 12, 15:02

These are the two most important commands when loading images:

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

Respondido 29 Oct 16, 07:10

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.