现在做的是平板的项目,需要在主界面同时显示webview,服务器有数据来,需要同时更新加载图形的数据,在低配置的手机上运行会使界面卡住,
在三星平板或者手机上运行还算流畅,经过排除,确定是因为webview的加载过慢导致界面卡顿,所以需要优化webview的加载速度,谷歌了一下,找到以下方法:
1.翻译一下英文大概的意思就是:设置渲染等级为高等、设置为硬件加速、不要有缓存数据
It depends on the web application being loaded. Try some of the approaches below:
Set higher render priority (deprecated from API 18+):
webview.getSettings().setRenderPriority(RenderPriority.HIGH);
Enable/disable hardware acceleration:
four_chart_webview.getSettings().setRenderPriority(RenderPriority.HIGH);
four_chart_webview.getSettings()
.setCacheMode(WebSettings.LOAD_NO_CACHE);
if (Build.VERSION.SDK_INT >= 11) {
four_chart_webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
} else {
four_chart_webview.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
2.还有一种是在主配置文件manifest中设置整个应用程序启动硬件加速,大概翻译的意思就是这样:
Adding this?android:hardwareAccelerated="true"?in the manifest was the only thing that significantly improved the performance for me
上述的硬件加速true和false我在手机上没有什么感觉
以下是问答的全文:http://stackoverflow.com/questions/7422427/android-webview-slow
在三星平板或者手机上运行还算流畅,经过排除,确定是因为webview的加载过慢导致界面卡顿,所以需要优化webview的加载速度,谷歌了一下,找到以下方法:
1.翻译一下英文大概的意思就是:设置渲染等级为高等、设置为硬件加速、不要有缓存数据
It depends on the web application being loaded. Try some of the approaches below:
Set higher render priority (deprecated from API 18+):
webview.getSettings().setRenderPriority(RenderPriority.HIGH);
Enable/disable hardware acceleration:
four_chart_webview.getSettings().setRenderPriority(RenderPriority.HIGH);
four_chart_webview.getSettings()
.setCacheMode(WebSettings.LOAD_NO_CACHE);
if (Build.VERSION.SDK_INT >= 11) {
four_chart_webview.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
} else {
four_chart_webview.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
2.还有一种是在主配置文件manifest中设置整个应用程序启动硬件加速,大概翻译的意思就是这样:
Adding this?android:hardwareAccelerated="true"?in the manifest was the only thing that significantly improved the performance for me
上述的硬件加速true和false我在手机上没有什么感觉
以下是问答的全文:http://stackoverflow.com/questions/7422427/android-webview-slow