Android 是否维护应用程序可绘制资源的内存缓存并重用它们,或者预加载可能动态分配给不同小部件的所有可绘制资源是一种好习惯?
例如:
public static final int[] SETS = {
R.drawable.set0, R.drawable.set1, R.drawable.set2,
R.drawable.set3, R.drawable.set4, R.drawable.set5, R.drawable.set6,
R.drawable.set7, R.drawable.set8, R.drawable.set9, R.drawable.set10};
public Drawable[] sets;
void init() {
load(sets, SETS);
}
public void load(Drawable[] d, int[] ids) {
for (int i = 0; i < ids.length; i++) {
if (ids[i] == 0)
d[i] = null;
else
d[i] = context.getResources().getDrawable(ids[i]);
}
}