Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scrollingCache?

Tags:

android

Can anybody explain the meaning of scrolling cache in Android. I stumbled upon this word, but was unable to find the explanation, either on android official website or on the web.

All I could find was how can I turn it on/off.

Thanks.

like image 879
Rajat Avatar asked Mar 22 '13 12:03

Rajat


2 Answers

Scrolling cache is basically a drawing cache.

In android, you can ask a View to store its drawing in a cache called drawing cache (basically a bitmap). By default, a drawing cache is disabled because it takes up memory but you can ask the View to explicitly to create one either via setDrawingCacheEnabled or through hardware layers (setLayerType).

So why is it useful? Because using a drawing cache make your animation smooth compared to redrawing the view at every frame.

This type of animation can also be hardware accelerated because the rendering system can take this bitmap and upload it to the GPU as a texture (if using hardware layers) and do fast matrix manipulations on it (like change alpha, translate, rotation). Compare that to doing animation were you are redrawing (onDraw gets called) on every frame.

In the case of a listview, when you scroll by flinging, you are in essence animating the views of your list (either moving them up or down). The listview uses the drawing cache of its visible children (and some potentially visible children near the edges) to animate them very quickly.

Is there a disadvantage to using drawing cache? Yes it consumes memory which is why by default it is turned off for in a View. In the case of ListView, the cache automatically created for you as soon as you touch the ListView and move a little (to differentiate a tap from scroll). In other words, as soon as ListView thinks you are about to scroll/fling it will create a scroll cache for you to animate the scroll/fling motion.

like image 51
numan salati Avatar answered Nov 11 '22 05:11

numan salati


scrollingCache is explained in full detail in the lecture of "the world of listView".

It's basically caches the scrolling itself so that it will move a bitmap, but according to my experience, it actually makes things much slower and take memory for nothing special.

scrollingCache is enabled by default, at least for listView . That's why if performance is important for you, you should consider disabling it.

like image 1
android developer Avatar answered Nov 11 '22 05:11

android developer