您的位置:首页 > 其它

ViewGroup提高绘制性能

2013-01-06 16:19 316 查看
http://www.jbtraining.com.cn/base/android/222.html

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);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: