图像未显示在 imageView 中

Image not getting displayed in imageView

为什么我的图片没有显示在 imageView 中?

    var image : Bitmap?=null

    longToast(obj?.image?.url.toString())

    try {
        image = BitmapFactory.decodeFile(obj?.image?.url.toString())
        imagePhoto.setImageBitmap(image)
        longToast("abc")
    } catch (e: Exception) {
        e.message
    }

图像不为空,因为我看到 toast 显示

https://...../tempory.jpg

BitmapFactory.decodeFile无法处理url

要从 url 加载图像,您可以使用 Glide,此库是由 Google 推荐的。来自文档:

Note: There are several libraries that follow best practices for loading images. You can use these libraries in your app to load images in the most optimized manner. We recommend the Glide library

将 Glide 添加到您的项目中:

dependencies {
  implementation 'com.github.bumptech.glide:glide:4.8.0'
  annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'
}

然后

Glide.with(context)
.load(obj?.image?.url.toString())
.into(imagePhoto)