private void facesinit() {
resIds = new int[68];
for (int i = 0; i < 68; i++) {
resIds[i] = makeFaceId(i);
}
}
/**
* 根据资源图片的名字构造、获取其R。drawable。_的值
* @param id
* @return
*/
private int makeFaceId(int id) {
Field field;
try {
if (id<10) {
field = R.drawable.class.getDeclaredField("f_static_00" + id);
return Integer.parseInt(field.get(null).toString());
}else {
field = R.drawable.class.getDeclaredField("f_static_0" + id);
return Integer.parseInt(field.get(null).toString());
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
return id;
}
根据文件名生成内存的资源id,即R.drawable中
最新推荐文章于 2022-07-09 11:52:03 发布