且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

机器人的WebView后期渲染

更新时间:2023-11-18 23:48:34

阿杰的回答给了我的东西,我用在另一个项目,所以我可以使的WebView 背景透明的提示。到现在我还不知道code关闭硬件加速。我测试了code,和平在这个项目中,也没有晚渲染了。虽然滚动页面是不是一帆风顺的,但之前它比后期渲染更好。

这是在code来解决这一切的:

 如果(Build.VERSION.SDK_INT> = 11)wv.setLayerType(WebView.LAYER_TYPE_SOFTWARE,NULL);
 

顺便说一句,这就像定义安卓hardwareAccelerated =假不影响的WebView

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

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');
}

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.

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

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

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

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);

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