Home » Android » java – WebView won't scroll in Android 2.x

java – WebView won't scroll in Android 2.x

Posted by: admin June 15, 2020 Leave a comment

Questions:

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>
How to&Answers:

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…

Answer:

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:

Answer:

What if you try to set this:

wView.getSettings().setUseWideViewPort(true);

Answer:

you could try enclosing your webview inside scrollview:

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

Answer:

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>

Answer:

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.