我有一个普通的ViewPager
,FragmentPagerAdapter
包含3个片段,它在所有Android手机上都非常流畅和漂亮,但是当我在Android平板电脑上试用它时,从第0页到1,然后它正常工作,因为我正在设置ViewPager.setOffscreenPageLimit(3);
。使用的所有三个片段在onCreateView
中都不做任何事情,它们只是设置按钮布局。
以下是我FragmentActivity
:
public void initializeMenuViewPager() {
menuViewPager = (ViewPager) findViewById(R.id.menu_viewPager);
menuViewPager.getLayoutParams().width = window_width / 3;
menuViewPager.setAdapter(new MenuViewPagerAdapter(getSupportFragmentManager(),
createFragments()));
menuViewPager.setOffscreenPageLimit(3);
}
public List<Fragment> createFragments() {
fragmets = new ArrayList<Fragment>();
fragmets.add(DashboardFragment.newInstance(zonesList, modesList,
currentZone, currentMode, loadingThrobber));
fragmets.add(CategoriesFragment.newInstance(window_width,
window_height, currentZone.getId()));
fragmets.add(PreferencesFragment.newInstance());
return fragmets;
}
这是我的MenuViewPagerAdapter
:
public class MenuViewPagerAdapter extends FragmentPagerAdapter {
private List<Fragment> fragments;
public MenuViewPagerAdapter (FragmentManager fm, List<Fragment> fragments) {
super(fm);
this.fragments = fragments;
}
@Override
public Fragment getItem(int position) {
Log.e("MenuViewPager", "getItem " + position);
return this.fragments.get(position);
}
@Override
public int getCount() {
return this.fragments.size();
}
}
任何帮助?