如何设置imageview src? [英] how to set imageview src?
问题描述
我有一个图像视图和一个字符串src.我想将imageview源设置为我拥有的 string src,但由于该方法需要一个int值,因此无法执行此操作:
I have an image view and a string src. I want to set the imageview source to the string src that I have, but am unable to do so beacuse the method expects an int:
imgview.setImageResource(int);
由于此方法需要一个int值,我如何才能实现使用字符串的目标?
Since this method takes an int how can I accomplish my goal of using a string?
推荐答案
每个图像都有一个资源编号,它是一个整数.将此数字传递给"setImageResource",您就可以了.
Each image has a resource-number, which is an integer. Pass this number to "setImageResource" and you should be ok.
检查此链接以获取更多信息:
http://developer.android.com/guide/topics/resources/accessing-resources.html
Check this link for further information:
http://developer.android.com/guide/topics/resources/accessing-resources.html
例如:
imageView.setImageResource(R.drawable.myimage);
这篇关于如何设置imageview src?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!