android 切换栏目 SmartTabLayout的使用

这个是整体布局xml布局(重点是红色部分,那个是栏目的布局)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">
<LinearLayout
    android:background="#d23d3d"
    android:layout_width="match_parent"
    android:layout_height="30dp">

</LinearLayout>
    <FrameLayout
        android:id="@+id/tab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

这个是我在界面实现的逻辑(我是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的布局

<?xml version="1.0" encoding="utf-8"?>
<com.ogaclejapan.smarttablayout.SmartTabLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/viewpagerTab"
    android:background="#d64848"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    app:stl_customTabTextLayoutId="@layout/item_tab"
    app:stl_customTabTextViewId="@+id/custom_texts"
    app:stl_indicatorColor="@color/red_text"
    app:stl_indicatorInterpolation="linear"
    app:stl_indicatorThickness="3dp"
    app:stl_underlineThickness="1dp"
    />



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值