How to show image using ImageView in Android(如何在 Android 中使用 ImageView 显示图像)
问题描述
我正在寻找将图像 src 分配给图像视图控件的方法.我读了几个例子,他们说了一些 src="QGRyYXdhYmxlaW1hZ2U="
但不明白这一点,我也想在运行时通过 java 代码分配图像 src 也想在 XML 中应用默认图像.
I am looking for the way to assign image src to image view control. I read few example and they says something src="QGRyYXdhYmxlaW1hZ2U="
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
文件夹中找到 drawable
文件夹.你可以把你的图片文件放在那里.
You'll find the drawable
folder(s) in the project res
folder. You can put your image files there.
这篇关于如何在 Android 中使用 ImageView 显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Android 中使用 ImageView 显示图像


- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01