4.QMUI----QMUITabSegment的用法

1. 引入库

1.最新的库会上传到 JCenter 仓库上,请确保配置了 JCenter 仓库源,然后直接引用:

compile 'com.qmuiteam:qmui:1.0.6'
至此,QMUI 已被引入项目中。

2.需要引用QMUI的样式

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

<style name="AppTheme" parent="QMUI.Compat.NoActionBar">
    
    <item name="colorPrimary">@color/colorPrimaryitem>
    <item name="colorPrimaryDark">@color/colorPrimaryDarkitem>
    <item name="colorAccent">@color/colorAccentitem>
style>

2. QMUITabSegment的用法

布局:
<com.qmuiteam.qmui.widget.QMUITabSegment
    android:id="@+id/tabSegment"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:background="@drawable/tab_panel_bg"
    />

<android.support.v4.view.ViewPager
    android:id="@+id/contentViewPager"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="@color/qmui_config_color_white"
    />
使用方法:
List fragments= new ArrayList<>();
CommercialLoansFragment mFirstFragment = new CommercialLoansFragment(0);
ProvidentFundLoanFragment mSecondFragment = new ProvidentFundLoanFragment(0);
LoanPortfolioFragment mthreeFragment=new LoanPortfolioFragment(0);;
fragments.add(mFirstFragment);
fragments.add(mSecondFragment);
fragments.add(mthreeFragment);
BaseFragmentPagerAdapter adapter = new BaseFragmentPagerAdapter(getSupportFragmentManager(), fragments);
mContentViewPager.setAdapter(adapter);
for (int i = 0; i mTabSegment.addTab(new QMUITabSegment.Tab("Item " + (i + 1)));
}
int space = QMUIDisplayHelper.dp2px(context, 16);
mTabSegment.setHasIndicator(true);
mTabSegment.setMode(QMUITabSegment.MODE_SCROLLABLE);  //MODE_SCROLLABLE 自适应宽度+滚动   MODE_FIXED  均分
mTabSegment.setItemSpaceInScrollMode(space);
mTabSegment.setupWithViewPager(mContentViewPager, false);
mTabSegment.setPadding(space, 0, space, 0);
private class BaseFragmentPagerAdapter extends FragmentPagerAdapter {
    private List mDataList;

    public BaseFragmentPagerAdapter(FragmentManager fm) {
        super(fm);
    }


    public BaseFragmentPagerAdapter(FragmentManager fm, List dataList) {
        super(fm);
        mDataList = dataList;
    }

    @Override
    public Fragment getItem(int position) {
        return mDataList.get(position);
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }
}



你可能感兴趣的:(QMUI)