Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollview Optimizations

I have a scrollview that contains a custom view. The custom view is bigger than the area of the screen and draws properly.

The scrollview however tends to call onDraw() non-stop when scrolling, and I can't seem to make it smooth.

I used ScrollView.getDrawingRect() to calculate the visible portion of the screen and only draw to that, but it still returns the entire viewport (so it's optimized to not draw offscreen areas), and not the delta between the last position and the current one. Ideally I'd want to draw only the delta, and not the entire visible window.

If anyone can point me to more information about how to use the drawing caches, and if that will help optimize scrolling, I'd love to implement it, or any other possible solutions it would be greatly appreciated.

like image 931
HaMMeReD Avatar asked Apr 06 '11 21:04

HaMMeReD


1 Answers

When content is scrolled, the entire viewport needs to be redrawn because all of the content has moved. I don't think there's anything that needs to be done to optimize a ScrollView - if scrolling is slow then it's the drawing method of your custom view that is too slow.

Try to avoid object creation in your draw methods which is usually the main culprit for poor drawing performance.

Edit: Also the scrollview could blit the old content up or down quickly that is still drawn on the screen, and then request a redraw of only the "new" portion of the screen. (only applies to opaque views).

like image 75
Joseph Earl Avatar answered Oct 09 '22 02:10

Joseph Earl