ViewGroup提高绘制性能
Viewgroup如果下面有很多子View。绘制的时候,需要开启其子View的绘制缓存。从而提高绘制效率。具体的代码如下
public void setChildrenDrawingCacheEnabled(boolean enabled) {final int count = getChildCount();for (int i = 0; i < count; i++) {final View view = getChildAt(i);view.setDrawingCacheEnabled(true);// Update the drawing caches view.buildDrawingCache(true);}}
另一方面也可以通过setDrawingCacheQuality(low),将缓存质量降低,减少内存。
最后结束的时候,需要通过以下代码来清空绘制缓存.
void clearChildrenCache() {final int count = getChildCount();for (int i = 0; i < count; i++) {final CellLayout layout = (CellLayout) getChildAt(i);layout.setChildrenDrawnWithCacheEnabled(false);}}
转自:http://blog.csdn.net/wukunting/article/details/6703183