如何从tmdb json feed加载电影的图像

时间:2015-07-09 12:20:35

标签: java android android-fragments android-recyclerview themoviedb-api

片段代码

//获取电影海报

                String urlPOster = null;

                if (currentMovies.has(KEY_POSTER)) {

                    urlPOster = currentMovies.getString(URL_POSTER +KEY_POSTER);
                }

URL_POSTER和KEY_POSTER

public static final String KEY_POSTER =“poster_path”;

public static final String URL_POSTER =“http://image.tmdb.org/t/p/w500”;

tmdb的json feed

results": [{
"adult": false,
"backdrop_path": "/o4I5sHdjzs29hBWzHtS2MKD3JsM.jpg",
"genre_ids": 
[878,
28,
53,
12],
"id": 87101,
"original_language": "en",
"original_title": "Terminator Genisys",
"overview": "The year is 2029. John Connor, leader of the resistance continues the war against the machines. At the Los Angeles offensive, John's fears of the unknown future begin to emerge when TECOM spies reveal a new plot by SkyNet that will attack him from both fronts; past and future, and will ultimately change warfare forever.",
"release_date": "2015-07-01",
"poster_path": "/5JU9ytZJyR3zmClGmVm9q4Geqbd.jpg",
"popularity": 55.202911,
"title": "Terminator Genisys",
"video": false,
"vote_average": 6.4,
"vote_count": 183},

这是我的适配器类

    final String urlPoster=currentMovies.getUrlPOster();
    if (urlPoster!=null){

        imageLoader.get(urlPoster, new ImageLoader.ImageListener() {
            @Override
            public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
                holder.movieThumbnail.setImageBitmap(response.getBitmap());
            }

            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });

1 个答案:

答案 0 :(得分:1)

建议 Glide,您可以加载自己的网址。

ImageView imageView = (ImageView) findViewById(R.id.you_image_view);
Glide.with(this)
  .load("http://image.tmdb.org/t/p/w500/o4I5sHdjzs29hBWzHtS2MKD3JsM.jpg")
  .into(imageView);