use of com.example.jingbin.cloudreader.view.MyFragmentPagerAdapter in project CloudReader by youlookwhat.
the class MainActivity method initContentFragment.
private void initContentFragment() {
ArrayList<Fragment> mFragmentList = new ArrayList<>();
mFragmentList.add(new GankFragment());
mFragmentList.add(new OneFragment());
mFragmentList.add(new BookFragment());
// 注意使用的是:getSupportFragmentManager
MyFragmentPagerAdapter adapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), mFragmentList);
vpContent.setAdapter(adapter);
// 设置ViewPager最大缓存的页面个数(cpu消耗少)
vpContent.setOffscreenPageLimit(2);
vpContent.addOnPageChangeListener(this);
mBinding.include.ivTitleGank.setSelected(true);
vpContent.setCurrentItem(0);
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
//去除默认Title显示
actionBar.setDisplayShowTitleEnabled(false);
}
}
use of com.example.jingbin.cloudreader.view.MyFragmentPagerAdapter in project CloudReader by youlookwhat.
the class BookFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
showLoading();
initFragmentList();
/**
* 注意使用的是:getChildFragmentManager,
* 这样setOffscreenPageLimit()就可以添加上,保留相邻2个实例,切换时不会卡
* 但会内存溢出,在显示时加载数据
*/
MyFragmentPagerAdapter myAdapter = new MyFragmentPagerAdapter(getChildFragmentManager(), mFragments, mTitleList);
bindingView.vpBook.setAdapter(myAdapter);
// 左右预加载页面的个数
bindingView.vpBook.setOffscreenPageLimit(2);
myAdapter.notifyDataSetChanged();
bindingView.tabBook.setTabMode(TabLayout.MODE_FIXED);
bindingView.tabBook.setupWithViewPager(bindingView.vpBook);
showContentView();
}
use of com.example.jingbin.cloudreader.view.MyFragmentPagerAdapter in project CloudReader by youlookwhat.
the class GankFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
showLoading();
initFragmentList();
/**
* 注意使用的是:getChildFragmentManager,
* 这样setOffscreenPageLimit()就可以添加上,保留相邻3个实例,切换时不会卡
* 但会内存溢出,在显示时加载数据
*/
MyFragmentPagerAdapter myAdapter = new MyFragmentPagerAdapter(getChildFragmentManager(), mFragments, mTitleList);
bindingView.vpGank.setAdapter(myAdapter);
// 左右预加载页面的个数
bindingView.vpGank.setOffscreenPageLimit(3);
myAdapter.notifyDataSetChanged();
bindingView.tabGank.setTabMode(TabLayout.MODE_FIXED);
bindingView.tabGank.setupWithViewPager(bindingView.vpGank);
showContentView();
// item点击跳转
initRxBus();
}
Aggregations