的WebView加载缓慢的Android? [英] WebView Loads slowly in android?
问题描述
我工作的一个web视图在一个应用程序,其中,当按钮是pressed含量的WebView负载变化(两个按钮旁边和previous,他们只是改变的WebView内容)。但在pressing 3-4次就开始挂在那里是没有打印任何的logcat,按钮依然pressed 15-20秒,然后下一个数据加载。
I am working on a webView in an app, where content which webview load changes when a button is pressed (two buttons next and previous , they just change the content in webview). But after pressing 3 -4 times it starts to hang there is nothing printed on logcat, the button remains pressed for 15-20 sec and then the next data is loaded.
我用这些来清除webview.db和缓存: -
I have used these to clear out webview.db and cache:-
context.this.deleteDatabase("webview.db");
context.this.deleteDatabase("webviewCache.db");
webView.getSettings().setRenderPriority(RenderPriority.HIGH);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
但它仍然hangs.How可以我加快步伐?请帮助?
But still it hangs.How can I speed it up?Please help?
更新:
public void setWebView(String QuestionParent,String QuestionNumber)
{
WebSettings webSettings = questionWeb.getSettings();
webSettings.setDefaultFontSize(24);
questionWeb.getSettings().setRenderPriority(RenderPriority.HIGH);
questionWeb.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
questionWeb.loadDataWithBaseURL("",integralParse.htmlParse(questionCode,"mnt/sdcard/faData/"+QuestionParent+"/"+QuestionNumber),"text/html","UTF-8","");
}
我使用的按钮preSS此方法。 integralParse.htmlParse()方法返回一个HTML文本。
I am using this method on button press. integralParse.htmlParse() method returns a html text .
推荐答案
您处理web视图导航是否正确?请参见本教程官方文档:
Are you handling webView navigation properly? See this tutorial on the official docs:
https://developer.android.com/guide/webapps/webview。 HTML#HandlingNavigation
如果你只是使用loadData(),那么你可以尝试清单文件中这样设置硬件加速:
if you are just using loadData() then you can try setting hardware acceleration on in the manifest file like this:
android:hardwareAccelerated="true"
在应用程序级别添加它,也就是在你的AndroidManifest.xml文件的标签
add it at the application level, i.e in the tag of your AndroidManifest.xml file
在这之后,它实际上取决于您的设备上。如果你有一个高端的设备,图像会很快呈现否则会需要一段时间,因为web视图使用webkit的硬件加速功能,这取决于您的设备配置。
After this point, it really depends on your device. If you have a high end device, images will be rendered quickly otherwise they will take time since webView is using webkit hardware acceleration and this depends on your device configuration.
如果你仍然需要的速度,你可以尝试做一个完全原生的应用程序没有web视图。一切都将是光滑如黄油。没有WebKit的,没有HTML和更大的控制权。
if you still need speed, you can try making a fully native app without webview. Everything will be smooth as butter. No webkit, no html and much greater control.
祝你好运: - )
这篇关于的WebView加载缓慢的Android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!