I have an app whose main navigation feature is a ViewPager with essentially infinite pages. I'm using something similar to [InfiniteViewPager](https://github.com/antonyt/InfiniteViewPager) (with a `FragmentStatePagerAdapter`), starting navigation in the middle of the ViewPager so there are pages to the left and right to start. I'm also using negative margins `mPager.setPageMargin(-50);` to have the pages on either side slightly visible.

I'm loading lots of data from the web, so I'm handling configuration changes myself by using `android:configChanges="orientation|keyboardHidden"` and the `onConfigurationChanged` override in my activity. Mainly, I don't want to recreate my Activity because I think it would take much too long when changing orientation.

Problem
-------

I open the app, swipe in either direction, wait for the ViewPager to stop animating, then change orientation. The current page is now slightly off center and one neighboring page is more exposed than the other. Sometimes one of the neighboring pages is completely offscreen.

If I touch the page, the ViewPager scroll to the current page and displays as expected, but unless I do that, the display is wrong. I get this problem going from Landscape to Portrait and Portrait to Landscape. I've tried setting a `OnGlobalLayoutListener` and performing `mViewPager.setCurrentItem(mViewPager.getCurrentItem())` but `ViewPager` ignores `setCurrentItem` if you ask it to set the current item to what is actually the current item.

Code
----

MainActivity

```
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    //whatever I do in here doesn't make a difference.
    //my viewpager still displays off center, even if I do nothing custom
}

```

Pager Adapter

```
private class MyAdapter extends FragmentStatePagerAdapter{

    public CarouselPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        PageData dataForThisPage = mModel.getDataForPage(position);
        PageContainerFragment f = PageContainerFragment.create(position, dataForThisPage);

        return f;
    }

    @Override
    public int getCount() {
        return 2000;
    }
}

```

I've been trying to figure this out for hours and I can't get anywhere. Any help would be greatly appreciated!

Edit: styling