问题描述
我是新的Android开发,寻找指定图像的src图像视图控件的方式。我看了几个例子,他们说了些什么 SRC =@可绘制\图像
,但不明白这一点,我也想在Java $ C $指定图像的src在运行时C也想申请默认图像以XML。
I am new to android development, looking for the way to assign image src to image view control. I read few example and they says something src="@drawable\image"
but didn't understand this, also I want to assign image src at runtime by java code also want to apply default image in XML.
感谢
推荐答案
如果你想显示在手机上的图像文件,你可以这样做:
If you want to display an image file on the phone, you can do this:
private ImageView mImageView;
mImageView = (ImageView) findViewById(R.id.imageViewId);
mImageView.setImageBitmap(BitmapFactory.decodeFile("pathToImageFile"));
如果你想从你绘制资源,显示图像,做到这一点:
If you want to display an image from your drawable resources, do this:
private ImageView mImageView;
mImageView = (ImageView) findViewById(R.id.imageViewId);
mImageView.setImageResource(R.drawable.imageFileId);
您会发现绘制
文件夹中的项目 RES
文件夹(S)。你可以把你的图像文件存在。
You'll find the drawable
folder(s) in the project res
folder. You can put your image files there.
这篇关于如何在Android中使用ImageView的显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!