FlycoTabLayout Documentation

repository·master·Indexed 27 days ago

https://github.com/h07000223/flycotablayout

An Android library providing three types of TabLayout components: SlidingTabLayout for ViewPager integration, CommonTabLayout for independent tab management, and SegmentTabLayout. It includes features for dynamic tab addition, smooth scrolling, and automated ViewPager and fragment configuration.

Tokens
880
Snippets
3
Records
12
Agent score
45%

What's inside FlycoTabLayout

  1. Install FlycoTabLayout via Gradle

    master

    Depending on whether your project uses AndroidX or the older Support Library, use the corresponding dependency configuration in your build.gradle file.

    // AndroidX
    dependencies {
        implementation 'io.github.h07000223:flycoTabLayout:3.0.0'
    }
    
    // Old
    dependencies{
        compile 'com.android.support:support-v4:23.1.1'
        compile 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar'
    }
  2. Configure ViewPager, titles, and fragments automatically

    master
    In version 1.1.6 and later, you can use setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, ArrayList<Fragment> fragments) to fully initialize the TabLayout. This method allows you to skip manual PageAdapter instantiation by providing the ViewPager, titles, the host FragmentActivity, and the list of fragments.
  3. Use SlidingTabLayout with ViewPager

    master

    The SlidingTabLayout is a modified version of PagerSlidingTabStrip that works in conjunction with a ViewPager. It provides convenience methods to set up the view without manually managing adapters or titles.

    /** no need to set titles in adapter */
    public void setViewPager(ViewPager vp, String[] titles)
    
    /** no need to initialize even adapter */
    public void setViewPager(ViewPager vp, String[] titles, FragmentActivity fa, ArrayList<Fragment> fragments)
  4. Set ViewPager and titles without a PageAdapter

    master
    In version 1.1.2 and later, you can use setViewPager(ViewPager vp, String[] titles) to configure the TabLayout with a ViewPager and an array of titles directly, bypassing the need to manually instantiate or manage a PageAdapter.
  5. Use CommonTabLayout for independent tab management

    master

    Unlike SlidingTabLayout, CommonTabLayout does not depend on a ViewPager. It can be used freely with other widgets and supports fragment switching internally.

    /** support switch fragments itself */
    public void setTabData(ArrayList<CustomTabEntity> tabEntitys, FragmentManager fm, int containerViewId, ArrayList<Fragment> fragments)