android:layout_height=“wrap_content”>
</android.support.design.widget.TabLayout>
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
/>
<light.lipengfei.club.myapplication.fragment.MyViewPager
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:id="@+id/viewpager">
<android.support.v4.view.PagerTitleStrip
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”>
</android.support.v4.view.PagerTitleStrip>
</light.lipengfei.club.myapplication.fragment.MyViewPager>>
主要java代码:
viewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public long getItemId(int position) {
return super.getItemId(position);
}
@Override
public Fragment getItem(int position) {
switch (position){
case 0:
return injecFragment;
case 1:
return httpFragment;
case 2:
return bitmapFragment;
case 3:
return dbFragment;
case 4:
return mapFragment;
}
return null;
}
@Override
public int getCount() {
return 5;
}
@Override
public CharSequence getPageTitle(int position) {
switch (p
《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》
【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享
osition){
case 0:
return “注解模块”;
case 1:
return “网络模块”;
case 2:
return “图像模块”;
case 3:
return “数据库模块”;
case 4:
return “地图模块”;
}
return null;
}
});
}
布局代码不变,viewpager
java主要代码
List fragmentList;
FragmentPagerAdapter fragmentPagerAdapter;
fragmentList=new ArrayList();
fragmentList.add(injecFragment);
fragmentList.add(httpFragment);
fragmentList.add(bitmapFragment);
fragmentList.add(dbFragment);
fragmentList.add(mapFragment);
fragmentPagerAdapter=new FragmentPagerAdapter(this.getSupportFragmentManager()){
@Override
public Fragment getItem(int position) {
return fragmentList.get(position);
}
@Override
public int getCount() {
return 5;
}
};
viewPager.setAdapter(fragmentPagerAdapter);
简单切换没有tab。
3.点击侧滑Dowerlayout的item,切换不同的fragment。()