关于为什么要优化UI,CPU,GPU是如何渲染图形图像的这里不作赘述,具体参考下面两篇优秀的blog,这里只是对这些blog中提出的方法的总结
1. UI渲染笔记1
3 UI优化
UI的优化方法
一.利用系统资源:
使用系统定义的id:例如XML文件中:android:id="@android:id/list
代码里引用findViewById(android.R.id.list);
使用系统定义的字符:android:text="@android:string/yes"
使用系统颜色:android:color="@android:color/transparent"
使用系统图片: android:icon="@*android:drawable/ic_menu_attachment"
使用系统style: android:textAppearence="?android:attr/textAppearenceMedium"
二.优化overdraw:
1.移除不必要的背景,这里要注意的是Activity的布局最终会添加到decorview中,所以可以将decorview的背景去掉,调用getWindow.setBackgroundDrawable(null);
2.绘制图像的时候使用cliprect防止图片叠加绘制
3.优化布局:
减少不必要的层次,默认最大布局深度为10
在布局中使用include,viewstub,merge等标签
使用组合控件