Is there a way to get WebView to refresh its image (view) while scrolling?

If I run javascript on the WebView while the WebView is scrolling (with a finger on the screen), the view is not updated with a new look until the finger is lifted from the device, and the scroll stops.

To test this, I redefine onScroll in WebView and there I call some javascript that changes the background of the page to a random color. This happens again and again when the page scrolls. Thus, you must quickly flash different colors while scrolling.

However, on a Nexus S with gingerbread and a galactic Nexus with an ice cream sandwich, the color only updates when scrolling stops.

But on Xoom with Honeycomb, color constantly updates as you scroll. This is the desired result.

Any ideas on what's different on other devices and how to get WebView to update itself when scrolling through the Xoom method?

Thanks!

Additional Information: Just to indicate that javascript is received and received during scrolling, but the image showing these changes does not appear until the scrolling is complete. For example, if the javascript you call is console.log ('rawr'); Logs are displayed while scrolling.

found something in the source code . There is a WebView method called startDrag () that calls WebViewCore.pauseUpdatePicture (mWebViewCore) , which prevents the image from updating while scrolling. In 3.0 they introduced WebSetting setEnabledSmoothTransition () , which you can see in code 4.0, allows you to disable the pause. However, this is only 3.0 or more, which means less than 3% in wild devices. Until now, I see no way to get around this in devices up to 3.0 ..... :(

+6
source share
3 answers

I believe that when the versions of Android 2.5 were scrolled to speed up the work, the screen was turned into a bitmap, and this scrolls, rather than redrawing every view that could potentially be on the screen. therefore, if you do not override this, the colors will no longer be drawn until the scroll stops

0
source

You can use OnTouchListener to capture the action of a finger on the scroll bar, redraw your graphics, and then transfer the movement of the finger back to the scroll bar before exiting onTouchListener.

0
source

What you can try is to implement OnTouchListener for your WebView when onTouchEvent is called in your browser. invalidate (); This causes the View to redraw itself.

0
source

Source: https://habr.com/ru/post/907898/


All Articles