android 切换栏目 SmartTabLayout的使用

这个是整体布局xml布局(重点是红色部分,那个是栏目的布局)





    

    

这个是我在界面实现的逻辑(我是Fragment里面实现)

 @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.columndotplayerfragment, container, false);
        viewPager = (ViewPager) view.findViewById(R.id.viewPager);
        mInfos = new ArrayList<>();
	//这个是String资源里面的数据,
	//修改里面的数据就可以修改栏目的名字
String[] titls = getResources().getStringArray(R.array.news_titles);
 
  
	//里面主要是栏目切换的Fragment
        for (int i = 0; i < titls.length; i++) {
            String title = titls[i];
            FragmentInfo info;
            if (i == 0) {
                info = new FragmentInfo(new DotPlayerFragment(), title);
            } else if (i == 1) {
                info = new FragmentInfo(new ConferenceFragment(), title);
            } else if (i == 2) {
                info = new FragmentInfo(new TrainFragment(), title);
            } else if (i == 3) {
                info = new FragmentInfo(new MediaFragment(), title);
            } else if (i == 4) {
                info = new FragmentInfo(new OfficialFragment(), title);
            } else if (i == 5) {
                info = new FragmentInfo(new BackstageFragment(), title);
            } else {
                info = new FragmentInfo(new OutPutLivePlayerFragment(), title);
            }
            mInfos.add(info);
        }
	//下面的代码
        FrameLayout tabs = (FrameLayout) view.findViewById(R.id.tab);
//include_tabs布局主要是修改栏目的UI比如染色,字体大小(),把布局放进tabs里面显示
tabs.addView(LayoutInflater.from(getContext()).inflate(R.layout.include_tabs, tabs, false));
 
  
        SmartTabLayout viewpagerTab = (SmartTabLayout) view.findViewById(R.id.viewpagerTab);
        viewPagerAdapter = new ViewPagerAdapter(getFragmentManager(), mInfos);
        viewPager.setAdapter(viewPagerAdapter);
        viewpagerTab.setViewPager(viewPager);
        return view;
    }


include_tabs的布局





你可能感兴趣的:(android)