常用第三方库的基本使用

 

0.场景

今天想自己做点新东西,发现一个常用的第三方库忘记了怎么使用了,不能每次都去百度吧。。。

1.多Tab页 

com.flyco.tablayout:FlycoTabLayout_Lib
XML中:
    <com.flyco.tablayout.CommonTabLayout
        android:id="@+id/tl"
        android:layout_width="match_parent"
        android:layout_height="@dimen/z88"
        android:background="#ffffff"
        android:paddingLeft="@dimen/z500"
        android:paddingRight="@dimen/z500"
        app:tl_iconVisible="false"
        app:tl_indicator_color="#3B8DE2"
        app:tl_indicator_width="@dimen/z200"
        app:tl_textBold="SELECT"
        app:tl_textSelectColor="#3B8DE2"
        app:tl_textUnselectColor="#999999"
        app:tl_textsize="@dimen/z32" />
    <android.support.v4.view.ViewPager
        android:id="@+id/vp"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginTop="@dimen/z40"
        android:layout_weight="1" />    
java中:
    private ViewPager mViewPager;//记得初始化
    private CommonTabLayout mTabLayout;//记得初始化
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private String[] mTitles = {"等待中", "接待中", "已完成"};
    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();

    private void initVP() {
        for (int i = 0; i < mTitles.length; i++) {
            mFragments.add(ConsultationContentFragment.newInstance(i, new Bundle()));
            mTabEntities.add(new TabEntity(mTitles[i]));
        }
        mViewPager.setAdapter(new MyPagerAdapter(getChildFragmentManager()));
        mTabLayout.setTabData(mTabEntities);
        mTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                mViewPager.setCurrentItem(position);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                mTabLayout.setCurrentTab(position);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        mViewPager.setOffscreenPageLimit(4);
        mViewPager.setCurrentItem(0);
    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

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

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

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

2.后面想起来了在更新吧...

先到这里吧,1024程序员节日快乐!

发布了43 篇原创文章 · 获赞 27 · 访问量 12万+

猜你喜欢

转载自blog.csdn.net/qq_30878303/article/details/83347120