问题描述
我想在imageview中显示图片,所以我在 res
中创建了一个文件夹 - drawable
并放置了我的图像那里。像 apple.png
之类的东西。然后我使用这段代码:
I want to show an image in imageview so I made a folder - drawable
in res
and put my image there. Something like apple.png
. Then I use this code:
ImageView iv= (ImageView)findViewById(R.id.img_selected_image);
String path = getApplication().getFilesDir().getAbsolutePath();
InputStream is = new FileInputStream(path + "/apple.png");
Drawable icon = new BitmapDrawable(is);
Log.i("Fnord", "width="+icon.getIntrinsicWidth()+
" height="+icon.getIntrinsicHeight());
iv.setImageDrawable(icon);
但是当我运行它时,它表示没有任何图像 apple.png
中的名称data / data / package-name / files
。我想我把我的形象放在了不适当的地方。我应该把我的图像放在哪里?
But when i run it, it said there isn't any image by apple.png
name in data/data/package-name/files
. I think i put my image in inappropriate place. Where should i put my image ?
推荐答案
你可以直接在你的setimage中给出图像名称 iv .setImageResource(R.drawable.apple);
应该是它。
you can directly give the Image name in your setimage as iv.setImageResource(R.drawable.apple);
that should be it.
这篇关于如何在android中的imageview中设置图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!