background

TabLayout and ViewPager2 binding class TabLayoutMediator can be very simple to implement TabLayout and ViewPager2 binding. This time we are in accordance with the idea of TabLayoutMediator TabLayout and RecyclerView binding

Introduction to the

TabLayoutMediator2 is a warehouse for binding TabLayout and RecyclerView and anchor location, which is very suitable for anchor location of e-commerce App commodity details page. And support for CoordinatorLayout+AppBarLayout+TabLayout+RecyclerView(TabLayout and RecyclerView do not overlap) and TabLayout+RecyclerView(TabLayout And RecyclerView).

Making the address

The effect

The principle of

The previous article has been introduced: article address, this time increased the TabLayout and RecyclerView overlap support, improve the demo

Method of use

Add in Gradle

dependencies {
		implementation 'the IO. Kailuzhang. Making. Tablayoutmediator2: tablayoutmediator2:0.1.0 from'
}
Copy the code

It can be called very simply

// Offset is the height of RecyclerView and TabLayout overlap
TabLayoutMediator2(
  tabLayout = binding.tabLayout,
  recyclerView = binding.itemList,
  tabCount = tabList.size,
  appBarLayout = binding.appbar,
  offset = 0, autoRefresh =false,
  tabConfigurationStrategy = object : TabLayoutMediator2.TabConfigurationStrategy {
    override fun onConfigureTab(tab: TabLayout.Tab, position: Int): IntArray {
      tabList[position].apply {
        tab.text = title
    		// Return the start and end viewTypes of the RecyclerView Adapter of the current TAB
        return intArrayOf(startViewType, endViewType)
      }
    }
  }
).attach()
Copy the code

Two use cases

  1. Non-overlapping (CoordinatorLayout+AppBarLayout+TabLayout+RecyclerView)

    This layout is the library control and TabLayout are placed in the AppBarLayout, RecyclerView under the AppBarLayout, offset = 0 in this case

  2. Overlapping situation (TabLayout+RecyclerView)

    This layout is a library control is used as a RecyclerView Item, TabLayout and RecyclerView overlap, offset = tablayot.height

The last

At present, the warehouse has been online. Our project (daily life is more than 500,000) has been running stably for more than 3 months.

If you find this library useful, welcome everyone star, thank you!

In addition, I am also looking for a job in Shanghai or Wuhan recently. I hope there is a big man who can help me push it inside, thank you!

Email address: [email protected]