标签:
// 初始化引导图片列表
view1 = inflater.inflate(R.layout.page_one, null);
view2 = inflater.inflate(R.layout.page_two, null);
view3 = inflater.inflate(R.layout.page_three, null);
viewList = new ArrayList<View>();// 将要分页显示的View装入数组中
viewList.add(view1);
viewList.add(view2);
viewList.add(view3);
viewPager = (ViewPager) findViewById(R.id.viewpager);
// 初始化Adapter,重写PagerAdapter
PagerAdapter pagerAdapter = new PagerAdapter() {
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;//该object其实就是viewPager添加的view
}
@Override
public int getCount() {
return viewList.size();
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView(viewList.get(position));
}
@Override
public int getItemPosition(Object object) {
return super.getItemPosition(object);
}
@Override
public CharSequence getPageTitle(int position) {
return super.getPageTitle(position);
}
@Override
public Object instantiateItem(View container, int position) {
((ViewPager)container).addView(viewList.get(position));
return viewList.get(position);
}
};
viewPager.setAdapter(pagerAdapter);
// 绑定回调
标签:
原文地址:http://www.cnblogs.com/fruitbolgs/p/4227598.html