简体   繁体   中英

Improve webview performance - android

I'm developing an application that use a webview which loads an Html & javascript files.

but the performance was too bad when its display the content!

I've tried many solutions like:

        webView.getSettings().setRenderPriority(RenderPriority.HIGH); 
    webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE); 
    webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);

but it's still remain the same.

Any advice or tips to enhance the performance?

If there's only some few components of your webview that is slow or laggy, try adding this to the elements css:

transform: translate3d(0,0,0);
-webkit-transform: translate3d(0,0,0);

This has been the only speedhack that really had a effect on my webview. But be careful not to overuse it! (you can read more about the hack in this article .)

尝试添加

webView.getSettings().setJavaScriptEnabled(true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM