Android webview loading data performance very slow

前端 未结 3 1966
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 13:24

Hi I am working on one application, In that I am using Android WebView. Whenever I launch webview activity, loading data in string html format from test.txt file. test.txt f

3条回答
  •  Happy的楠姐
    2020-11-27 14:05

    I think the following works best:

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

    Android 19 has Chromium engine for WebView. I guess it works better with hardware acceleration.

    For more info Android 4.4 KitKat, the browser and the Chrome WebView

    Hardware Acceleration also do's the trick.You can use it in different levels in your application.

    Application level

    
    

    Activity level

    
        
        
    
    

    Window level

    getWindow().setFlags(
        WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
        WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
    

    View level

    myView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    

    But as already mentioned in your question can you elaborate the side effects for this ?

提交回复
热议问题