带有Picasso的ViewPager未在RecyclerView Row中加载

时间:2016-12-20 12:43:48

标签: android android-viewpager android-recyclerview

我的recyclerview中有一个viewPager用于任何有图像的帖子,图像正在被检索并加载到毕加索中,但我的回收者视图没有显示它。知道我做错了什么吗?

这是我的RecyclerView适配器调用ViewPager适配器

      if (posts.getPost().getImages() != null) {

            ImagePagerAdapter pagerAdapter = new ImagePagerAdapter(mContext, posts.getPost().getImages());
            holder.imageViewPager.setAdapter(pagerAdapter);

        }

然后这是我的imagePagerAdapter

public class ImagePagerAdapter extends PagerAdapter {

private Context mContext;
private ArrayList<PostImageBundle> postImages = new ArrayList<>();

public ImagePagerAdapter(Context context, ArrayList<PostImageBundle> postImageBundles) {
    this.mContext = context;
    this.postImages = postImageBundles;
}

@Override
public int getCount() {
    return postImages.size();
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    container.removeView((LinearLayout) object);
}

@Override
public boolean isViewFromObject(View view, Object object) {
    return (view == (LinearLayout) object);
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
    LayoutInflater inflater = (LayoutInflater) container.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.pager_image_item, null);

    ImageView imageView = (ImageView) view.findViewById(R.id.imagePost);
    Picasso.with(mContext)
            .load(postImages.get(position).getMedium().getUrl())
            .into(imageView);

    container.addView(view);

    return view;
}
}

知道我做错了什么吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

我忘了为我的ViewPager设置一个固定的高度....这就是问题