The Viewpager function is to make the view slide. Can be used to do navigation, page menu. Adapter Pageradapter is required for use. Therefore, the need to inherit the pageradapter, the implementation of the boot interface requires at least 4 methods: Instantiateitem (ViewGroup, int): Used to create a page at a specified location; Destroyitem (ViewGroup, int, Object): Destroys a page at the specified location; GetCount (): number of pages; Isviewfromobject (View, Object) : Used to determine whether a view of pager is associated with the object returned by the Instantiateitem method.
// 初始化引导图片列表
VI Ew1 = Inflater inflate ( r layout page_one null );
VI Ew2 = 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 ( viewgroup container int 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);
// 绑定回调
Reference: http://blog.csdn.net/wangjinyu501/article/details/8169924
From for notes (Wiz)
Android App boot interface-viewpages use