Android的绘图资源:有什么办法整型标识以某种方式连接到R绘制的ID? [英] Android drawables : Is there any way to somehow link the int IDs to the R drawable IDs?
问题描述
我在 718可绘绘-MDPI
,绘制,华电国际
和绘-xhdpi
文件夹,他们的名字都1.png,2.png ......到718.png。 (他们实际上是神奇宝贝精灵)
I have 718 drawables in the drawable-mdpi
, drawable-hdpi
and drawable-xhdpi
folders, whose names are 1.png, 2.png... to 718.png. (They are actually Pokémon sprites)
因此,根据不同的神奇宝贝,我想要加载其中一人表现出来。但是,我不能用数字直接识别第r绘制ID。
So, depending on the Pokémon, I want to load one of them to show it. However, I cannot use the number to directly identify the R drawable ID.
有什么办法(除了一个718例开关或的Hashmap&LT的;整数,整数GT;
)?整型标识以某种方式连接到R绘制的ID
Is there any way (besides of a 718-case switch or a Hashmap<Integer,Integer>
) to somehow link the int IDs to the R drawable IDs?
推荐答案
您可以尝试:
String sprite = "drawable/"+number;
int imageResource = getResources().getIdentifier(sprite, null, getPackageName());
的绘制
是图像的文件夹。在数量
是你想要的图像数量。例如1.png
The drawable
is the folder where the image is in. The number
is the number of the image you want. e.g. 1.png
这篇关于Android的绘图资源:有什么办法整型标识以某种方式连接到R绘制的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!