问题描述
涉及:
http://stackoverflow.com/questions/2307374/need-suggetsion-about-a-mixed-uri-int-id-images-ambient
现在我的问题是:
ImageView imgView=(ImageView)findViewById(R.id.imgView);
Uri imgUri=Uri.parse("android.resource://my.package.name/"+R.drawable.image);
imageView.setImageURI(imgUri);
不起作用。为什么呢?
does NOT work . why?
我知道
imgView.setImageDrawable(Drawable.createFromStream(
getContentResolver().openInputStream(imgUri),
null));
工作
但是,这并不解决我的问题。因为我想设置与URI independenty的形象,如果这是来自一个资源或来自相机ACTION_PICK意图...
but that does NOT solve my problem. because I want to set the image with an uri independenty if this come from a resource or come from the camera ACTION_PICK intent...
任何建议,欢迎。谢谢。问候
any suggestions are welcome.Thank you.Regards
推荐答案
试试这个
Uri imgUri=Uri.parse("android.resource://my.package.name/"+R.drawable.image);
imageView.setImageURI(null);
imageView.setImageURI(imgUri);
这是一个解决方法刷新一个ImageButton的,它试图缓存previous图像URI。传递空
有效地重置了。
This is a workaround for refreshing an ImageButton, which tries to cache the previous image Uri. Passing null
effectively resets it.
解决方案从本书中提出:将由Sams Android应用开发在24小时内 - 高度推荐阅读。
Solution suggested from this book: Sams Teach Yourself Android Application Development in 24 Hours - Highly recommendable to read.
不要忘记投票了,如果这个回答你的问题。
Don't forget to vote up if this answers your question.
这篇关于试图分配R.drawable.X乌里时ImageView.setImageURI不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!