Not sure if this is what your looking for but sounds like you would like to limit the views loaded either side of the displayed view.
This may help:
//BEGIN_INCLUDE Fragment onViewCreated
public void onViewCreated(View view, Bundle savedInstanceState) {
// BEGIN_INCLUDE (setup_viewpager)
// Get the ViewPager and set it's PagerAdapter so that it can display items
mViewPager = (ViewPager) view.findViewById(R.id.viewpager);
//setOffscreenPageLimit() allows the viewpager to maintain state as it's swiped. the chronometer will keep running as the page is swiped
//This may need to be adjusted as the app gets more tabs ADDED 3-31-15
mViewPager.setOffscreenPageLimit(8);//8 screens loaded and maintain state
}
Notice the setOffscreenPageLimit()
method.
Try setting this to 0 or 1.
From the Documentation (in the class, the Android Developer website does not offer this kind of specificity)
/**
* Set the number of pages that should be retained to either side of the
* current page in the view hierarchy in an idle state. Pages beyond this
* limit will be recreated from the adapter when needed.
*
* This is offered as an optimization. If you know in advance the number
* of pages you will need to support or have lazy-loading mechanisms in place
* on your pages, tweaking this setting can have benefits in perceived smoothness
* of paging animations and interaction. If you have a small number of pages (3-4)
* that you can keep active all at once, less time will be spent in layout for
* newly created view subtrees as the user pages back and forth.
*
* You should keep this limit low, especially if your pages have complex layouts.
* This setting defaults to 1.
*
* @param limit How many pages will be kept offscreen in an idle state.
*/
You can experiment to find a value that you want.