Android中如何实现将具有相同特征的id循环获得

如果你要用到的图片资源的id是具有连续特征的,你如何通过循环获得呢?
例如图片资源是(如果实在drawable目录下,当然也可以在mipmap目录下(如果是mipmap下列字符串对应改变)):
ic_img_pc_01
ic_img_pc_02
ic_img_pc_03
ic_img_pc_04
ic_img_pc_05
for(int i = 0 ; i < 5 ; i++){
int id=getResources().getIdentifier(“ic_img_pc_0”+i,”drawable”,getPackageName());
Drawable drawablege=getResource().getDrawable(id);
}

猜你喜欢

转载自blog.csdn.net/qq_35920289/article/details/72312327