Android WebView 性能 [英] Android WebView performance

查看:26
本文介绍了Android WebView 性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我在 webview 中加载外部 url 列表并允许用户浏览它们.Webviews 被加载到一个视图翻转器上.我发现 webview 加载 url 的性能非常糟糕.我已经尝试了从使用框架布局到限制要加载的 web 视图数量的所有方法.表现还是不尽如人意.

In my app, I am loading a list of external url's in webview and allow user to flip through them. Webviews are loaded on to a view flipper. I find the performance is really bad in webview load url. I have tried everything from using the frame layout to limiting the number of webviews to load. Still the performance is not satisfactory.

如何优化webview的性能?这应该是一个常见的用法.我是否遗漏了一些明显的东西.

How do I optimize the performance of webview? This should be a common usage. Am I missing something obvious.

我的 Webview 设置是 -

My Webview settings are -

    webView.setInitialScale(WEBVIEW_SCALE);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setBuiltInZoomControls(false);
    webView.setWebViewClient(new MyWebViewClient());    
    webView.setOnTouchListener( new OnTouchListener());

推荐答案

试试这个:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    webView.setLayerType(View.LAYER_TYPE_HARDWARE, null); 
} else {
    webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

这篇关于Android WebView 性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆