// viewpager_view_01.xml
// viewpager_view_02.xml
// activity.main.xml
<android.support.v4.view.ViewPager
android:id="@+id/main_viewPager"
android:layout_width="match_parent"
android:layout_height="130dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="#000">
</android.support.v4.view.ViewPager>
// MainActivity.java
viewPager=(ViewPager)findViewById(R.id.main_viewPager);
LayoutInflater inflater=getLayoutInflater();
view01=inflater.inflate(R.layout.viewpager_view01,null);
view02=inflater.inflate(R.layout.viewpager_view02,null);
viewlist=new ArrayList<View>();
viewlist.add(view01);
viewlist.add(view02);
PagerAdapter pagerAdapter=new PagerAdapter() {
@Override
public int getCount() {
return viewlist.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view==object;
}
@Override
public void destroyItem(ViewGroup container,int position, Object object){
container.removeView(viewlist.get(position));
}
@Override
public Object instantiateItem(ViewGroup container,int position){
container.addView(viewlist.get(position));
return viewlist.get(position);
}
};
viewPager.setAdapter(pagerAdapter);