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>
4

6 回答 6

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:

于 2013-06-19T10:11:48.927 回答
2

如果您仍然有问题

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

如果您想在页面仍在加载时显示 ProgressBar,请使用

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

            }

        });

希望这可以帮助...

于 2013-06-21T14:21:13.050 回答
2

如果你尝试设置这个怎么办:

wView.getSettings().setUseWideViewPort(true);
于 2013-06-14T16:06:29.370 回答
2

您可以尝试将您的 webview 包含在滚动视图中:

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

于 2013-06-17T12:27:29.077 回答
2

修改您的 XML 以改用 ScrollView。将工作。

<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>
于 2013-06-20T03:54:01.413 回答
1

3x+ 有很多改进,android webview 有太多限制 http://androiddeveloperuser.blogspot.in/2011/05/webview-part-1-capabilities-and.html

在这里,我将在一篇关于限制和优势的 android 博客中写下简短的内容

有很多事件是不能被拦截的,并且可以重载哪些行为是有限制的,这就限制了这个组件的定制,改变这个组件的默认行为很困难。

于 2013-06-20T17:08:43.540 回答