WebView功能将无法呈现,直到触及的Andr​​oid 4.2.2 [英] WebView fails to render until touched Android 4.2.2

查看:522
本文介绍了WebView功能将无法呈现,直到触及的Andr​​oid 4.2.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个名为闪电浏览器的开源浏览器,我所遇到的最近期更新到Android(4.2.2)一些麻烦。

WebViews将无法呈现完全直到视图感动。它只发生在最新的Andr​​oid版本。在4.2.1中,web视图呈现完全没问题。我用我的Nexus 7的开发和之后,我收到了4.2.2更新,浏览器停止渲染。其他用户遇到这个问题,以及,并证实多次发生只在4.2.2。这是发生针对API级别16和17,但我已经看到了WebKit浏览器为目标的A​​PI级别9没有这个问题。

我试图用这个解决一个问题,我在这里找到的堆栈溢出(补救<一个href="http://stackoverflow.com/questions/13500452/android-webview-renders-blank-white-view-doesnt-update-on-css-changes-or-html">Android的WebView呈现空白/白,鉴于对CSS的变化或HTML变化不更新,动画是波涛汹涌)。然而,仅在web视图的RenderPriority设置为高没有解决它...得到它,而不触及呈现唯一的办法就是将无效()命令的WebView的的OnDraw()方法中。这导致的WebView不断地重新绘制。这工作(在某种程度上),动画是光滑的,页面加载速度非常快,但它会导致web视图的性能下降,否则。

我也看到了这个问题(非常类似于我的),但它没有很好的答案。 <一href="http://stackoverflow.com/questions/10387345/android-webview-fails-to-completely-render-content-until-user-interaction">Android的WebView无法完全呈现内容,直到用户交互

通过性能下降,我的意思是输入。文本输入滞后,以及web视图本身无法处理正在发生的事情,以及前。标杆与无效()方法调用浏览器降至基准业绩约8%。我知道基准是不是万能的,但它告诉我,连续绘图拉紧系统,造成系统忽略其他任务。

在总结... 在安卓4.2.2的WebView不会渲染,直到感动。我知道解决这个问题的唯一方法是调用无效()在web视图的的OnDraw()方法。这是坏的表现,我正在寻找一种不同的方式来解决这个问题。

魔术code(我目前使用的)...

 类MyWebView扩展的WebView
{
    @覆盖
    的OnDraw(帆布油画)
    {
        无效();
        super.OnDraw(画布);
    }
}
 

删除

 无效();
 

和它不渲染,直到感动。

有没有人对如何使web视图渲染(不是我做了什么其他的)一个建议?顺便说一句,这是我的第一个问题,我在这里对堆栈问,所以请原谅我,如果我还没有搞清楚,或者如果我做错了什么。

编辑: 我发现这个问题,<一个href="http://stackoverflow.com/questions/11344125/android-chromium-disk-cache-error-corrupt-index-file">here有关类似问题,而且还解决了,问题是,我不明白答案甚至意思。如果有人可以开导我,这可能会有帮助。

我得到的logcat此错误

  E /铬(1243):外部/铬/ NET / disk_cache / backend_impl.cc:2022:0705/172030:ERROR:backend_impl.cc(2022)]损坏的索引文件
 

解决方案

所以,我终于找到了问题导致的WebView不渲染。我开始和停止绘制的动画我的WebView的WebViewClient内。这可绘制的是一个简单的刷新按钮旋转时,页面加载...简单吧?

井在浏览器的非全屏模式,旋转抽拉和web视图是相同的父的两个孩子,而在全屏幕模式,被拉伸变成web视图的子项。不知何故,通过启动动画时,页面加载和停止它,当它完成(全屏),应用程序决定该旋转绘制是需要所有的绘图能力和​​web视图从来没有平局。当在全屏模式下被拉伸成为web视图的孩子,那么web视图具有更高优先级的渲染比绘制,并提请罚款。

这个故事的寓意是...... WebViews想成为最优先视图绘制。如果有获得更大的优先级等的意见,他们不会正确绘制。

我在动画方面的专家,所以我需要重新考虑我的动画绘制现在,以不中断的WebView。

希望这是有道理的。感谢您的阅读。

I am developing an open-source browser called Lightning Browser, and I have run into some trouble with the most recent update to Android (4.2.2).

WebViews will fail to render completely until the view is touched. It only occurs on the latest Android version. On 4.2.1, the WebView rendered completely fine. I use my Nexus 7 for development and right after I received the 4.2.2 update, the browser stopped rendering. Other users experienced this as well, and it was confirmed multiple times to happen ONLY on 4.2.2. It is happening targeting API level 16 and 17, but I have seen a WebKit browser that targets API level 9 without this problem.

I have attempted to remedy this using the solution to a problem I found here on Stack Overflow (Android WebView renders blank/white, view doesn't update on css changes or HTML changes, animations are choppy). HOWEVER, setting the WebView's RenderPriority to high alone does not solve it... the only way to get it to render without being touched was to place the invalidate() command inside the OnDraw() method of WebView. This causes the WebView to re-draw continuously. This works (sort of), animations are smooth, the page loads very quickly, but it causes the WebView's performance to drop otherwise.

I have also seen this question (very similar to mine), but there is no good answer for it. Android WebView Fails to Completely Render Content Until User Interaction

By performance drop, I mean input. Text input lags, and the WebView itself cannot handle what is going on as well as before. Benchmarking the browser with the invalidate() method call drops Benchmarking performance by around 8%. I know benchmarks aren't everything, but it's telling me that the continuous drawing is straining the system and causing the system to ignore other tasks.

In Conclusion... The WebView in Android 4.2.2 will not render until touched. The only way I know to fix this is to call invalidate() in the onDraw() method of WebView. This is bad for performance and I am looking for a different way to fix this.

The Magic Code (I'm currently using)...

class MyWebView extends WebView
{
    @Override
    onDraw(Canvas canvas)
    {
        invalidate(); 
        super.OnDraw(canvas);
    }
}

remove

invalidate();

and it doesn't render until touched.

Does anyone have a suggestions on how make the WebView render (other than what I've done)? By the way, this is my first question I've asked here on Stack, so forgive me if I haven't been clear or if I've done something wrong.

EDIT: I found this question here about a similar issue and it was resolved, the problem is, I don't understand what the answer even means. If anyone could enlighten me it might help.

I get this error in logcat

E/chromium(1243): external/chromium/net/disk_cache/backend_impl.cc:2022: [0705/172030:ERROR:backend_impl.cc(2022)] Corrupt Index file

解决方案

So I finally found the issue causing the WebView not to render. I am starting and stopping the animation of a drawable inside the WebViewClient of my WebView. This drawable is simply a refresh button that rotates when the page is loading... simple right?

Well in the non-fullscreen mode of the browser, the rotating drawable and the WebView are both children of the same parent, whereas in the fullscreen mode, the drawable becomes a child of the WebView. Somehow, by starting the animation when the page is loading and stopping it when it's done (in fullscreen), the application decides that the rotating drawable is what needs all the drawing power and the WebView never draws. When in fullscreen mode and the drawable becomes a child of the WebView, the WebView then has a higher rendering priority than the drawable and it draws fine.

The moral of the story is... WebViews like to be the highest priority view to be drawn. If there are other views that get greater priority, they won't draw correctly.

I'm no expert on animations, so I need to rethink how I'm animating the drawable now so as to not interrupt the WebView.

Hopefully that made sense. Thanks for reading.

这篇关于WebView功能将无法呈现,直到触及的Andr​​oid 4.2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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