Search in sources :

Example 1 with MyFragmentPagerAdapter

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);
    }
}
Also used : GankFragment(com.example.jingbin.cloudreader.ui.gank.GankFragment) MyFragmentPagerAdapter(com.example.jingbin.cloudreader.view.MyFragmentPagerAdapter) ArrayList(java.util.ArrayList) OneFragment(com.example.jingbin.cloudreader.ui.one.OneFragment) BookFragment(com.example.jingbin.cloudreader.ui.book.BookFragment) GankFragment(com.example.jingbin.cloudreader.ui.gank.GankFragment) BookFragment(com.example.jingbin.cloudreader.ui.book.BookFragment) Fragment(android.support.v4.app.Fragment) OneFragment(com.example.jingbin.cloudreader.ui.one.OneFragment) ActionBar(android.support.v7.app.ActionBar)

Example 2 with MyFragmentPagerAdapter

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();
}
Also used : MyFragmentPagerAdapter(com.example.jingbin.cloudreader.view.MyFragmentPagerAdapter)

Example 3 with MyFragmentPagerAdapter

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();
}
Also used : MyFragmentPagerAdapter(com.example.jingbin.cloudreader.view.MyFragmentPagerAdapter)

Aggregations

MyFragmentPagerAdapter (com.example.jingbin.cloudreader.view.MyFragmentPagerAdapter)3 Fragment (android.support.v4.app.Fragment)1 ActionBar (android.support.v7.app.ActionBar)1 BookFragment (com.example.jingbin.cloudreader.ui.book.BookFragment)1 GankFragment (com.example.jingbin.cloudreader.ui.gank.GankFragment)1 OneFragment (com.example.jingbin.cloudreader.ui.one.OneFragment)1 ArrayList (java.util.ArrayList)1