private final class ImageViewAdapter extends PagerAdapter {
private List<view> views = null;
/**
* 初始化数据源, 即View数组
*/
public ImageViewAdapter(List<view> views) {
this.views = views;
}
/**
* 从ViewPager中删除集合中对应索引的View对象
*/
@Override
public void destroyItem(View container, int position, Object object) {
((ViewPager) container).removeView(views.get(position));
}
/**
* 获取ViewPager的个数
*/
@Override
public int getCount() {
return views.size();
}
/**
* 从View集合中获取对应索引的元素, 并添加到ViewPager中
*/
@Override
public Object instantiateItem(View container, int position) {
((ViewPager) container).addView(views.get(position), 0);
return views.get(position);
}
/**
* 是否将显示的ViewPager页面与instantiateItem返回的对象进行关联
* 这个方法是必须实现的
*/
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
}
01.ViewPager使用Demo
最新推荐文章于 2024-08-10 08:17:23 发布