1

I've a webview that I want to load a website and when I load it, it doesn't go right and left. It just goes up/down. (pan/scroll actions)

This is the code:

WebView wb=(WebView)findViewById(R.id.webView1);
WebSettings settings = wb.getSettings();
settings.setDefaultTextEncodingName("utf-8");
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
settings.setSaveFormData(false);
settings.setSupportZoom(true);

Thanks.

nunofmendes
  • 3,731
  • 2
  • 32
  • 42
Navid Abutorab
  • 1,667
  • 7
  • 31
  • 58

1 Answers1

3

You can achieve that with:

settings.setUseWideViewPort(true);

But you should read more about it in Android SDK Documentation:

public synchronized void setUseWideViewPort (boolean use)

Added in API level 1 Sets whether the WebView should enable support for the "viewport" HTML meta tag or should use a wide viewport.

When the value of the setting is false, the layout width is always set to the width of the WebView control in device-independent (CSS) pixels.

When the value is true and the page contains the viewport meta tag, the value of the width specified in the tag is used. If the page does not contain the tag or does not provide a width, then a wide viewport will be used.

Parameters

use whether to enable support for the viewport meta tag

More info @  http://developer.android.com/reference/android/webkit/WebSettings.html#setUseWideViewPort(boolean)

Community
  • 1
  • 1
nunofmendes
  • 3,731
  • 2
  • 32
  • 42
  • thanks for the reply , I use this , the problem is that it now want to show the whole website like a browser and there are lots of free and unused space on the page ,How to solve that ? – Navid Abutorab Nov 02 '14 at 13:37
  • You can fiddle with setInitialScale or the zoom.Check @ http://developer.android.com/reference/android/webkit/WebView.html#setInitialScale(int) – nunofmendes Nov 02 '14 at 13:40
  • Or you can try: setLoadWithOverviewMode(true) in settings. In Docs you can read: "Sets whether the WebView loads pages in overview mode, that is, zooms out the content to fit on screen by width.". More @ http://developer.android.com/reference/android/webkit/WebSettings.html#setLoadWithOverviewMode(boolean) – nunofmendes Nov 02 '14 at 13:42