Android进阶

TabLayout_ViewPager_Fragment可滑动的

2017-04-12  本文已影响19人  JianLee

一:先看布局


二:创建VierPagerAdapter

public classVierPagerAdapterextendsFragmentStatePagerAdapter{

privateListmFragment=newArrayList<>();

publicVierPagerAdapter(FragmentManagerfm){

super(fm);

initFragemnts();

}

private voidinitFragemnts(){

mFragment.add(newFragmentInfo("推荐",RecommendFragment.class));

mFragment.add(newFragmentInfo("排行",RankingFragment.class));

mFragment.add(newFragmentInfo("游戏",GameFragment.class));

mFragment.add(newFragmentInfo("分类",CategoryFragment.class));

}

@Override

publicFragmentgetItem(intposition){

try{

return(Fragment)mFragment.get(position).getFragment().newInstance();

}catch(InstantiationExceptione){

e.printStackTrace();

}catch(IllegalAccessExceptione){

e.printStackTrace();

}

return null;

}

@Override

public intgetCount(){

returnmFragment.size();

}

@Override

publicCharSequencegetPageTitle(intposition){

returnmFragment.get(position).getTitle();

}

}


三:Viewpage设置adapter+Tablayout.setupWithViewPager(myViewpage) 

上一篇 下一篇

猜你喜欢

热点阅读