scrollingCache?scrollingCache

2023-09-05 10:56:15 作者:ゝ浅默淡殇ヽ

有人能解释在Android的滚动缓存的含义。我偶然发现了这个词,但未能找到解释,无论是在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.

感谢。

推荐答案

滚动缓存基本上是一个绘图缓存。

Scrolling cache is basically a drawing cache.

在Android的,你可以要求查看存储的图中一个叫做绘图缓存缓存(基本上是一个位图)。默认情况下,绘图缓存被禁用,因为它占用的内存,但你可以要求查看明确要么通过setDrawingCacheEnabled或通过硬件层(setLayerType)创建一个。

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.

这类型的动画,也可以硬件加速,因为渲染系统可以把这个位图,并把它上传到GPU的纹理(如果使用的硬件层),做快速的矩阵操作就可以了(如改变字母,翻译,旋转)。与此相比,做动画是你正在重绘(OnDraw中被调用)对每一帧。

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.

在ListView的情况下,当你通过滚动丢,你在本质上是动画列表的视图(或者把他们向上或向下)。 ListView控件使用其可见孩子们的绘画缓存(和一些靠近边缘可能看到孩子们)非常迅速,以它们的动画。

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.

有没有使用绘图缓存吃亏?是的,它消耗的内存,这也就是为什么在默认情况下它被关闭了在视图中。在ListView控件的情况下,缓存自动为您只要你触摸ListView和动了一下(区分滚动水龙头)创建的。换句话说,只要ListView的认为你是要滚动/扔它会创建一个滚动缓存为您动画滚动/一扔运动。

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.

相关推荐