只需在在适配器中将getCount 给一个较大的值, 然后将currentItem 设为值的一半 就可以伪实现 无限循环.
private static final int PAGE_COUNT = 600; class MyPagerAdapter extends PagerAdapter { @Override
public int getCount() {
return PAGE_COUNT;
} @Override
public void notifyDataSetChanged() {
super.notifyDataSetChanged();
} @Override
public void destroyItem(ViewGroup container, int position, Object object) {
// container.removeView(viewList.get(position % viewList.size()));
} @Override
public Object instantiateItem(ViewGroup container, final int position) {
ImageView imageView = viewList.get(position % viewList.size());
try {
container.addView(imageView);
} catch (Exception e) { }
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, NewsDetailActivity.class);
intent.putExtra("subject", topList.get(position % viewList.size()));
startActivity(intent);
}
});
return imageView;
} @Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}