Android webview 延迟渲染 [英] Android webview late rendering

查看:80
本文介绍了Android webview 延迟渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我主要用 JS (Mootools) 和 HTML 编写了一个应用程序,它被加载到我的应用程序的 webview 中.

I've written an app mostly in JS (Mootools) and HTML which is loaded into webview in my app.

这只是一个 html 文件,它通过添加或删除 nodisplay 类来显示或隐藏页面的部分(元素):

It's just one html file which show or hide parts (elements) of the page by adding or removing a nodisplay class:

.nodisplay {display:none}
function showPage1()
{
     $$('.pages').addClass('nodisplay');
     $('page1').removeClass('nodisplay');
}

在android 4(xperia arc 和galaxy note 2)中,我看到一个奇怪的后期渲染,但我不知道旧版本的行为.当我隐藏一个元素并显示另一个元素时,它起初看起来是正确的,但在滚动期间,旧元素的某些部分会出现几毫秒并立即消失.就像不可见区域的渲染被推迟到绘图时刻.

In android 4 (xperia arc and galaxy note 2) I see a strange late rendering, but I don't know how older versions behave. when I hide an element and show another one, it appears correct at first but during scrolling some parts of the old elements appears for milliseconds and disappears immediately. It's like the render of non visible area is postponed to drawing moment.

有时它会在隐藏和显示过程中奇怪地眨眼.

And also sometime it just do odd blinks during hiding and showing.

在 PC 上的 chrome 中它没有任何问题.即使在 AVD 中,它也非常清晰,没有任何闪烁.

In chrome on PC it don't have any problem. Even in the AVD it works very sharp without any blinks.

不知道是不是android的问题,有没有办法克服?!

I don't know if it's a problem of android and if there is any way to overcome it?!

我试过 android:hardwareAccelerated="false"|"true" ,没有效果.还有 ws.enableSmoothTransition() 也不能解决问题.

I tried android:hardwareAccelerated="false"|"true" , no effect. and also ws.enableSmoothTransition() which doesn't solve the problem neither.

推荐答案

Ajay 的回答给了我一些我在另一个项目中使用过的东西的暗示,所以我可以使 WebView 背景透明.直到现在我都不知道代码会关闭硬件加速.我在这个项目中测试了代码的和平,不再有延迟渲染.虽然滚动页面不如以前流畅,但比延迟渲染要好.

Ajay answer gave me a hint of something I used in another project so I could make WebView background transparent. Till now I didn't know that code turns off hardware acceleration. I tested that peace of code in this project and there is no late rendering anymore. although scrolling the page is not as smooth as before but it's better than late rendering.

这是解决所有这些问题的代码:

This is the code to fix all of this:

if (Build.VERSION.SDK_INT >= 11) wv.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);

顺便说一下,这就像定义 android:hardwareAccelerated="false" 不影响 webview

By the way, it's like defining android:hardwareAccelerated="false" doesn't affect webview!

这篇关于Android webview 延迟渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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