8

I have a problem with the WebView. I am opening a Webpage in this WebView and it won't scroll in Android 2.x, but it will scroll in Android 3.x+.

Any Idea what can I do to fix that?

This is the configuration i use for this WebView:

wView = (WebView) findViewById(R.id.webView1);
wView.getSettings().setJavaScriptEnabled(true);
wView.setHorizontalScrollBarEnabled(true);

And in the Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00000000"
    tools:context=".MainActivity" 
    android:orientation="vertical">

    <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="horizontal" />

</LinearLayout>
smholloway
  • 589
  • 7
  • 14
Styler2go
  • 604
  • 2
  • 12
  • 32
  • Is this the case for all sites you try or just this particular page? – Ken Wolf Jun 16 '13 at 08:53
  • 1
    Potentially it is something in the javascript or css of the site that is not supported by older browsers. Try testing with the native browser on the older device. Does it work there? I have a feeling it's not your code... – Ken Wolf Jun 19 '13 at 10:00
  • Ken is absolutely right. If this is only happening for one site, then it is the site, not the `WebView`. – Cat Jun 20 '13 at 04:49
  • But, if this is not my Site, how can i fix it that it keeps working? Something like downloading the Site and editing the HTML Code on the Device...? – Styler2go Jun 20 '13 at 08:04
  • Can you post the url you're having trouble with? – Larry McKenzie Jun 21 '13 at 00:40

6 Answers6

6

Something in the css or javascript of that site is not supported by older Android browsers, it's not related to your code.

It's a little too broad to answer definitively - you'll need to test your site for compliance on different browsers. If you are using any specific libraries on your site you'll need to check their compatability.

Here are some links that may help:

Ken Wolf
  • 23,133
  • 6
  • 63
  • 84
  • Can i delete not supported functions that i can scroll? There are some Elements position fixed; which could be the problem. – Styler2go Jun 19 '13 at 13:49
  • Sure. Really the only option is hopefully you have the ability to change the site, you'll have to trial and error it a bit. Impossible to say for sure what is causing it from here! – Ken Wolf Jun 19 '13 at 13:50
  • If this is not my Site, how can i edit the HTML on the Device? – Styler2go Jun 20 '13 at 08:05
  • Yes but it will not be very straightforward. Implement your own WebViewClient or get the HTML first using HTTPClient http://stackoverflow.com/questions/3479833/is-it-possible-to-get-the-html-code-from-webview – Ken Wolf Jun 20 '13 at 08:09
  • An own WebViewClient can modify the HTML? – Styler2go Jun 20 '13 at 08:14
  • Maybe better to use HTTPClient to get/change the HTML first, then pass it to your webview as described in this solution http://stackoverflow.com/a/3482047/833647 – Ken Wolf Jun 20 '13 at 08:19
2

What if you try to set this:

wView.getSettings().setUseWideViewPort(true);
Enrichman
  • 11,157
  • 11
  • 67
  • 101
2

you could try enclosing your webview inside scrollview:

<LinearLayout ...... > <HorizontalScrollView ..... > <WebView .... /> </HorizontalScrollView> </LinearLayout>

MMss
  • 324
  • 3
  • 9
2

Modify your XML to use ScrollView instead. Will work.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
tools:context=".MainActivity" 
android:orientation="vertical">

    <ScrollView 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
        <WebView
        android:id="@+id/webView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="horizontal" />
    </ScollView>
</LinearLayout>
Siddharth
  • 9,349
  • 16
  • 86
  • 148
2

In case if you still have problem

    WebView wv = (WebView) v.findViewById(R.id.webview);
    wv.getSettings().setSupportZoom(true);
    wv.getSettings().setBuiltInZoomControls(true);
    wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
    WebSettings settings = wv.getSettings();        
    settings.setUseWideViewPort(true);
    settings.setJavaScriptEnabled(true);
    settings.setSupportMultipleWindows(true);
    settings.setJavaScriptCanOpenWindowsAutomatically(true);
    settings.setLoadsImagesAutomatically(true);
    settings.setLightTouchEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setLoadWithOverviewMode(true);
    wv.loadUrl("http://www.google.com");

in case if you want to show ProgressBar while the page is still loading use

     ProgressBar pb = (ProgressBar).findViewById(R.id.webview_progressBar1);

     wv.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return super.shouldOverrideUrlLoading(view, url);
            }

            @Override
            public void onPageFinished(WebView view, String url) {

                super.onPageFinished(view, url);

                pb.setVisibility(View.INVISIBLE);

            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {

                super.onPageStarted(view, url, favicon);

                pb.setVisibility(View.VISIBLE);

            }

        });

hope this helps...

ashish.n
  • 1,234
  • 14
  • 30
1

There are many of improvement has come in 3x+ , there too many limitation of android webview http://androiddeveloperuser.blogspot.in/2011/05/webview-part-1-capabilities-and.html

here i am going to past short line of contain written in one android blog written about limitation and advantage

There are many events that cannot be intercepted, and there is limitation in what behaviours can be overloaded, which limits the customization of this component and changing the default behaviour of this component difficult.

dharmendra
  • 7,835
  • 5
  • 38
  • 71