即使當我設置oViewPager.setOffscreenPageLimit(0)時,我的視圖分頁器仍然在可見頁面的每一側加載1個關閉屏幕頁面。ViewPager.setOffscreenPageLimit(0)完全沒有效果。我如何只在ViewPager中一次加載一個頁面?
如何使它只有用戶幻燈片時加載的頁面呢?
我的適配器是否有幫助:
public class MainPagerAdapter extends FragmentPagerAdapter {
protected static final String[] CONTENT = new String[] { "page 1", "page 2", "page 3", "page 4", };
private int mCount = CONTENT.length;
public MainPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
//return TestFragment.newInstance(CONTENT[position % CONTENT.length]);
return MainFragment.newInstance(position);
}
@Override
public int getCount() {
return mCount;
}
@Override
public CharSequence getPageTitle(int position) {
return MainPagerAdapter.CONTENT[position % CONTENT.length];
}
public void setCount(int count) {
if (count > 0 && count <= 10) {
mCount = count;
notifyDataSetChanged();
}
}
}
那麼解決方案是什麼? – code511788465541441