只有两个图像进入 Viewpager 其余的是空白的,它存在于 recyclerview 适配器中?

only two Images are coming in Viewpager rest are blank which is present in a recyclerview adapter?

我正在自定义 recyclerview 中的 viewpager 中加载图像,但所有图像都没有出现在 imagview 中,只有前两张图像出现了我已经调试了总共 6 张图像来自 api url

这是我的 viewpager 适配器代码

@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
    ImageView imageView = new ImageView(context);
    String url = context.getResources().getString(R.string.URL) + "media/" + imageUrls[position];

    Picasso.get()
            .load(url)
            .fit()
            .centerCrop()
            .into(imageView);
    container.addView(imageView);

    return imageView;
}

这是我的recyclerview部分

  @NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    profiles profile = getItem(position);
    //image stuff
    if (convertView == null) {
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.cards, parent, false);
    }
    ViewPagerAdapter viewPagerAdapter;
    ViewPager userImageViewPager;
    userImageViewPager = convertView.findViewById(R.id.userImageViewPager);

    String[] imageUrls = new String[]{};
    if (profile.getImages() != null) {
        imageUrls = profile.getImages();
        viewPagerAdapter = new ViewPagerAdapter(context, imageUrls);
        userImageViewPager.setAdapter(viewPagerAdapter);

    }

谁能帮帮我,我已经被困了几个小时了。

致电

userImageViewPager.setOffscreenPageLimit(imageUrls.length - 1)

after/before 设置 viewpageradapter