先上图看效果:
知识要点:
-
轮播图是怎么做到无限循环的呢
让ViewPagerAdapter里面的getCount返回MAX_VALUE,instantiateItem方法中,获取图片的时候,让position % drawableList.size(),来得到真实值
</@Override public int getCount() { return Integer.MAX_VALUE; } @NonNull @Override public Object instantiateItem(@NonNull ViewGroup container, int position) { if (drawableList != null && drawableList.size() > 0) { View imageView = null; if (mCache.isEmpty()) { imageView = new ImageView(mContext); }else { imageView = mCache.remove(0); } ((ImageView) imageView).setImageDrawable(drawableList.get(position % drawableList.size())); container.addView(imageView); return imageView; } return null; }