5

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: Half screen scroll ViewPager

2
  • 2
    Hi, here is a blog, might help commonsware.com/blog/2012/08/20/… Commented Aug 19, 2013 at 9:18
  • Awesome! This is exactly what I need! You saved me a lotof time! Commented Aug 19, 2013 at 10:14

1 Answer 1

15

Thanks to TeeTracker's comment I found the solution for your problem. I just had to Override getPageWidth in my Adapter:

@Override public float getPageWidth(int position) { return(0.5f); } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.