我正在使用ViewPager和Fragments。我偏移量設置爲1(我知道它是默認值),但它仍然在開始時加載三頁(0 - > 1 - > 2)而不是兩個(0 - > 1)...這裏有什麼問題?Android ViewPager加載太多頁面
private ViewPager mPager;
private PagerAdapter mPagerAdapter;
...
mPager = (ViewPager) findViewById(R.id.viewpager);
mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
mPager.setAdapter(mPagerAdapter);
mPager.setOffscreenPageLimit(1);
...
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
if (position == 0) {
return new InitializationFragment();
} else if (position == 8) {
return new InitializationFragment();
} else if (position == 9) {
return new SummaryFragment();
} else {
return new IngredientFragment(PizzaStage.values()[position - 1], layout);
}
}
@Override
public int getCount() {
return NUM_PAGES; //10
}
}