scrollingCache?

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.


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.


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.


I think you are talking about the following:

Imagine a list of 50 items where only 10 items are visible. Android will cache the next and previous (estimate) 5 items in a list item.

When you start scrolling through the list it will reuse the invisible item views, using the ArrayAdapter's function getView() For example if you are scrolling to the top it will take a view on the bottom and place it on top with new data.

So scrolling cache are the next and previous items above/under the visible items.

链接地址: http://www.djcxy.com/p/24186.html

上一篇: 当我尝试运行hellogridview时出错

下一篇: scrollingCache?