有没有办法找到绘制资源ID [英] is there any way to find resource Id of drawable
问题描述
有没有办法让绘制资源ID?例如,我使用的是ImageView的,我也可以在开始时使用的icon.png作为自己的形象,但后来我可以改变图像icon2.png。我想找出使用code表示哪个图像我的ImageView是从资源利用。有什么办法?
Is there any way to get the Drawable resource ID? For example, I am using an ImageView and I may initially use icon.png as its image but later I may change the image to icon2.png. I want to find out using the code that which image my ImageView is using from the resource. Is there any way?
推荐答案
您试图确定什么的电流的图像上的的ImageView
,以便将其切换到其他的形象呢?
Are you trying to determine what the current image is on the imageview
, in order to change it to some other image?
如果这是如此,我建议做的一切使用code,而不是XML。
If that's so I suggest doing everything using code instead of xml.
即。使用 setImageResource()
初始化时设定的初始的图像和跟踪资源的id
正在使用某个地方在code。
i.e. Use setImageResource()
to set the initial images during initialization and keep track of the resource ids
being used somewhere in your code.
例如,你可以有 imageviews
阵列与 INT
的相应的数组包含资源ID
每个的ImageView
For example, you can have an array of imageviews
with a corresponding array of int
that contains the resource id
for each imageview
然后,只要你想通过数组来改变形象,环路,看到了id是什么。
Then, whenever you want to change the image, loop through the array and see what the id is.
这篇关于有没有办法找到绘制资源ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!