我不确定自己错过了什么,但我一直试图通过使用Picasso库的themoviedb API在gridview中显示最受欢迎的电影海报。谁知道我做错了什么?
这是我的ImageAdapter:
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return 20;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
// if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
Picasso.with(mContext).load("https://api.themoviedb.org/3/movie/popular?api_key={APIKEY_HERE}&poster_path&images").into(imageView);
} else {
imageView = (ImageView) convertView;
}
return imageView;
}
}
答案 0 :(得分:1)
你必须检查picasso中的url它返回整个数据而不是图像url,尝试将poster_path的值添加到右url
答案 1 :(得分:1)
上面提到的API将给出热门电影列表..
results: [
{
poster_path: "/inVq3FRqcYIRl2la8iZikYYxFNR.jpg",
adult: false,
overview: "life.",
release_date: "2016-02-09",
backdrop_path: "/nbIrDhOtUpdD9HKDBRy02a8VhpV.jpg",
popularity: 91.92864,
vote_count: 3497,
video: false,
vote_average: 7.2
}
]
提取要显示的影片图像的poster_path 使用以下网址显示图片http://image.tmdb.org/t/p/w500/inVq3FRqcYIRl2la8iZikYYxFNR.jpg
您可以在http://docs.themoviedb.apiary.io/#reference/configuration/configuration
找到该文档