在某些情况下,Android webview不显示网页

men*_*a00 2 android android-webview html5-video

我有一个基于alfresco android sdk的应用程序.用户登录服务器后,MainActivity启动.MainActivity本身几乎没有碎片.一个片段包含webview,一些按钮和textview.这是xml布局的代码:

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/prop"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:orientation="vertical" >

            <LinearLayout
                android:id="@+id/video_layout"
                android:layout_width="match_parent"
                android:layout_height="192dp"          
                android:orientation="horizontal"
                android:gravity="center" >

                <WebView
                    android:id="@+id/video_web_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" /> 

            </LinearLayout>
                .
                .
                . 
        </LinearLayout>
 </ScrollView>
Run Code Online (Sandbox Code Playgroud)

显示布局时,webview应加载包含HTML5视频的页面网址,但仅显示空白页面.一段时间后,空白页面变为灰色.我观察到它意味着页面已加载,并在用户滚动布局后显示带有html5视频的页面.我尝试过的每个网址都会发生这种情况.

在测试活动中,我使用相同的布局,并且正确加载和显示带有视频的页面.

在片段和测试活动中,我使用相同的代码来设置webview并加载url.Javascript已启用,我使用WebChromeClient,就像WebView docummentation中推荐的那样.我在应用程序清单中也有INTERNET权限.

以下是来自测试活动的onCreate方法的代码:

protected void onCreate(Bundle savedInstanceState){         
        super.onCreate(savedInstanceState);     
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.web_video);
            web = (WebView)findViewById(R.id.video_web_view);
                .
                .
                .
            web.setWebChromeClient(new WebChromeClient());
            WebSettings webSettings = web.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setAllowContentAccess(true);
        webSettings.setAllowFileAccess(true);
            webSettings.setPluginState(PluginState.ON);
        webSettings.setDomStorageEnabled(true);
        web.setHorizontalScrollBarEnabled(false);
        web.setVerticalScrollBarEnabled(false);
        webSettings.setRenderPriority(RenderPriority.HIGH);     
        webSettings.setUseWideViewPort(false);
        webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
            web.loadUrl(someUrl);
}
Run Code Online (Sandbox Code Playgroud)

相同的代码包含片段中的onCreateView.唯一的区别是用户必须登录服务器才能显示片段.

我几乎忘记了Logcat的错误:

02-28 09:34:20.832: V/chromium(9079): external/chromium/net/host_resolver_helper/host_resolver_helper.cc:66: [0228/093420:INFO:host_resolver_helper.cc(66)] DNSPreResolver::Init got hostprovider:0x5354b220
02-28 09:34:20.832: V/chromium(9079): external/chromium/net/base/host_resolver_impl.cc:1515: [0228/093420:INFO:host_resolver_impl.cc(1515)] HostResolverImpl::SetPreresolver preresolver:0x018ee018
02-28 09:34:21.182: V/WebRequest(9079): WebRequest::WebRequest, setPriority = 1
02-28 09:34:21.382: V/chromium(9079): external/chromium/net/disk_cache/hostres_plugin_bridge.cc:52: [0228/093421:INFO:hostres_plugin_bridge.cc(52)] StatHubCreateHostResPlugin initializing...
02-28 09:34:21.392: V/chromium(9079): external/chromium/net/disk_cache/hostres_plugin_bridge.cc:57: [0228/093421:INFO:hostres_plugin_bridge.cc(57)] StatHubCreateHostResPlugin lib loaded
02-28 09:34:21.392: V/chromium(9079): external/chromium/net/disk_cache/hostres_plugin_bridge.cc:63: [0228/093421:INFO:hostres_plugin_bridge.cc(63)] StatHubCreateHostResPlugin plugin connected
02-28 09:34:21.392: V/chromium(9079): external/chromium/net/http/http_cache.cc:1167: [0228/093421:INFO:http_cache.cc(1167)] HttpCache::OnBackendCreated HostStat created
02-28 09:34:21.392: E/chromium(9079): external/chromium/net/disk_cache/stat_hub.cc:213: [0228/093421:ERROR:stat_hub.cc(213)] StatHub::Init - App org.alfresco.mobile.android.samples isn't supported.
02-28 09:34:21.392: E/chromium(9079): external/chromium/net/disk_cache/stat_hub.cc:213: [0228/093421:ERROR:stat_hub.cc(213)] StatHub::Init - App org.alfresco.mobile.android.samples isn't supported.
02-28 09:34:22.222: D/skia(9079): notifyPluginsOnFrameLoad not postponed
Run Code Online (Sandbox Code Playgroud)

有谁知道我做错了什么?有人有什么建议可以帮助我吗?

谢谢你的回答,抱歉我的英语不好.

men*_*a00 7

所以我弄清楚我做错了什么.它与加速有关.我只是在我的代码中添加以下行:

mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Run Code Online (Sandbox Code Playgroud)

它解决了我的问题.