I have a list of Fragments that I have to put in a ViewPager (no problem so far).
ArrayList<Fragment> fragmentList = new ArrayList<Fragment>(); fragmentList.add(new fragment1()); fragmentList.add(new fragment2()); fragmentList.add(new fragment3()); fragmentList.add(new fragment4()); FragmentAdapter mAdapter = new FragmentAdapter( mFragmentManager, fragmentList); mPager = (ViewPager) view.findViewById(R.id.pager_items_list); mPager.setCurrentItem(0); mPager.setAdapter(mAdapter); mPager.setOnPageChangeListener(pageChangeListener); The adapter
public class FragmentAdapter extends FragmentStatePagerAdapter { ArrayList<Fragment> fragmentsList; public FragmentAdapter(FragmentManager fm, ArrayList<Fragment> fragmentsList) { super(fm); this.fragmentsList = fragmentsList; } @Override public int getCount() { return fragmentsList.size(); } @Override public Fragment getItem(int position) { if (position<fragmentsList.size() & fragmentsList.get(position)!=null) { return fragmentsList.get(position); } return null; } } What I need is to make the ViewPager to show two items on the screen, but scroll only by one every time.
This image may help me explain what I mean: 