llguanli
View组件显示的内容能够通过cache机制保存为bitmap, 主要有下面方法:

void  setDrawingCacheEnabled(boolean flag), 

Bitmap  getDrawingCache(boolean autoScale), 

void  buildDrawingCache(boolean autoScale), 

void  destroyDrawingCache()

我们要获取cache首先要通过setDrawingCacheEnable方法开启cache,然后再调用getDrawingCache方法就能够获得view的cache图片了。

buildDrawingCache方法能够不用调用。由于调用getDrawingCache方法时,若果cache没有建立,系统会自己主动调用buildDrawingCache方法生成cache。

若想更新cache, 必需要调用destoryDrawingCache方法把旧的cache销毁。才干建立新的。

当调用setDrawingCacheEnabled方法设置为false, 系统也会自己主动把原来的cache销毁。

   
另外,ViewGroup在绘制子view时,也提供了两个方法

void setChildrenDrawingCacheEnabled(boolean enabled) 

setChildrenDrawnWithCacheEnabled(boolean enabled) 

setChildrenDrawingCacheEnabled方法能够使viewgroup里全部的子view开启cache;

setChildrenDrawnWithCacheEnabled使在绘制子view时。若该子view开启了cache, 则使用它的cache进行绘制。从而节省绘制时间。

获取cache一般会占用一定的内存,所以通常不须要的时候有必要对其进行清理,通过destroyDrawingCache或setDrawingCacheEnabled(false)实现。

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-02-12
  • 2021-09-14
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2021-06-09
  • 2021-08-08
猜你喜欢
  • 2021-05-21
  • 2021-12-10
  • 2021-10-19
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案