如何在android的imageview中设置图像? [英] How to set image in imageview in android?

查看:19
本文介绍了如何在android的imageview中设置图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 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);

但是当我运行它时,它说 data/data/package-name/files 中没有任何 apple.png 名称的图像.我想我把我的形象放在不合适的地方.我应该把我的图片放在哪里?

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中的Image命名为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中设置图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆