如何从drawable文件夹动态获取图像 [英] how to get images dynamically from drawable folder
本文介绍了如何从drawable文件夹动态获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的数组.
int image[] = {R.drawable.d002_p001,R.drawable.d002_p002,R.drawable.d002_p003,
R.drawable.d002_p004,R.drawable.d002_p005,R.drawable.d002_p006};
现在我有 6 张图片,所以我的名字是静态的.
Right now I have 6 images so I am statically given the name.
如果我有大约 50 张图像,我无法给出数组中的每个文件名,因此它需要是动态的,我该如何实现这一点.
If I have some 50 images I cant give each and every file name in array so it needs to be dynamic how can I achieve this.
推荐答案
您可以使用 getIdentifier()
for (int j = 1; j < 6; j++) {
Drawable drawable = getResources().getDrawable(getResources()
.getIdentifier("d002_p00"+j, "drawable", getPackageName()));
}
这篇关于如何从drawable文件夹动态获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文