适配器实施是直截了当的
private Context context;
private String images[];
public PagerAdapter(Context context) {
this.context = context;
}
public void setImages(String images[]) {
this.images = images;
notifyDataSetChanged();
}
public boolean areArrayTheSame(String images[]) {
return Arrays.equals(this.images, images);
}
@Override
public int getCount() {
if (images != null) {
return images.length;
} else {
return 0;
}
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, final int position) {
View itemView = LayoutInflater.from(context).inflate(R.layout.cover_image_item, container, false);
ImageView imageView = (ImageView) itemView.findViewById(R.id.coverImageIv);
Glide.with(context).load(images[position]).into(imageView);
container.addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
Recycler View仅启动并加载持有者一次
mPagerAdapter.setImages(coverPictures);
mViewPager.setAdapter(adapter);
mCircleIndicator.setViewPager(mViewPager);
故障真的很奇怪。第一次,它可以滑动,但是当您向下滚动并返回到此视图支架时,第一次滑动会变得很糟糕。它几乎跳过滑动,使视图立即出现。虽然进一步的幻灯片变好了 向下滚动回收器 - 查看和备份会创建相同的方案。
有什么建议吗?