Android WebView仅在单击/滚动后显示内容

问题描述 投票:2回答:2

我正在编写一个包含Web视图的Android应用,该应用会加载包含相当大形式的页面。在加载表单期间,我显示了一个进度栏。当进度条消失时,我通常只会看到一个空白页或表单的一些元素(例如很少的复选框,没有文本)。在尝试滚动页面(单击)之后,所有内容都会显示出来。知道这里有什么问题吗?

Webview的设置为:

mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDatabaseEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.getSettings().setAppCacheMaxSize(1024*1024*128);
mWebView.getSettings().setAppCachePath(getActivity().getApplicationContext().getCacheDir().getAbsolutePath());
mWebView.getSettings().setAllowFileAccess(true);
mWebView.getSettings().setAppCacheEnabled(true);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
mWebView.setWebChromeClient(new WebChromeClient() {
       @Override
       public void onExceededDatabaseQuota(String url,
                            String databaseIdentifier,
                            long currentQuota,
                            long estimatedSize,
                            long totalUsedQuota,
                            WebStorage.QuotaUpdater quotaUpdater)
       {
           quotaUpdater.updateQuota(estimatedSize * 2);
       }
    });
mWebView.addJavascriptInterface(new WebFormJavascriptInterface(), "jsinterface");
mWebView.getSettings().setRenderPriority(RenderPriority.HIGH);
mWebView.getSettings().setPluginState(android.webkit.WebSettings.PluginState.ON_DEMAND);

布局文件为:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:hardwareAccelerated="false"
    android:persistentDrawingCache="all"
/>
<ProgressBar
    android:id="@+id/progressbar"
    style="@android:style/Widget.Holo.ProgressBar.Large"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:indeterminate="true"
    android:visibility="gone"/>
</RelativeLayout>
android android-webview
2个回答
2
投票

我遇到其他问题,但是遇到了这个问题。正在执行

webview.postInvalidateDelayed(1500);

onPageFinished()中,在WebView声明中1.5秒后,new WebViewClient(){}几乎可以帮助自己刷新。不过,可能有比这个更好的答案了


1
投票

您是否覆盖WebViewClient?当重写WebViewClient的onPageStarted()和onPageFinished()方法,并删除super.onPageStarted()和super.onPageFinished()时,我遇到相同的问题。WebView首先加载空白页并在我触摸屏时显示内容。super(super.onPageStarted(),super.onPageFinished())的返回方法解决了我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.