首页 > 解决方案 > TMdb 的 ImageURL 问题?

问题描述

我正在编写一个程序(用于学习目的)。它基本上是一个显示来自 TMdb 的热门电影的 recyclerView。一切正常,但我的主要问题是 API 中的 Json 代码显示 ImageURL 或“Poster_path”,如下所示:

"page":1,
   "results":[
      {
         "adult":false,
         "backdrop_path":"/srYya1ZlI97Au4jUYAktDe3avyA.jpg",
         "genre_ids":[
            14,
            28,
            12
         ],
         "id":464052,
         "original_language":"en",
         "original_title":"Wonder Woman 1984",
         "overview":"Wonder Woman comes into conflict with the Soviet Union during the Cold War in the 1980s and finds a formidable foe by the name of the Cheetah.",
         "popularity":2942.16,
         "poster_path":"/8UlWHLMpgZm9bx6QYh0NFoq67TZ.jpg",
         "release_date":"2020-12-16",
         "title":"Wonder Woman 1984",
         "video":false,
         "vote_average":7.1,
         "vote_count":2853
      },

遗憾的是我在我的应用程序中看不到海报,我正在使用 Glide 来显示海报。任何人都可以帮助我吗?顺便说一句,我怎样才能在这里粘贴 Json?如您所见,它没有格式化?

标签: javaandroidjson

解决方案


  1. 首先检查您是否正在添加图像的完整 URL,它应该是“https://image.tmdb.org/t/p/original/srYya1ZlI97Au4jUYAktDe3avyA.jpg”

  2. 尝试使用毕加索库,添加毕加索的依赖:

实施 'com.squareup.picasso:picasso:2.3.0'

并添加recyclerview的代码如下:

Picasso.with(context).load(IMAGE_PREFIX + movie.getImagePath()).resize(500,500)
            .placeholder(R.drawable.movieplaceholder2)
            .into(holder.movieImage);

推荐阅读