Irurueta Android Recycler Tab Layout

This documentation was generated with the assistance of AI. Please report any inaccuracies.

RecyclerTabLayout is an Android view similar in appearance to Material’s TabLayout, but built on top of RecyclerView.

Why it exists

TabLayout creates a view for every tab up front. That is not appropriate when there are many tabs, or when each tab contains complex or memory-intensive views such as image thumbnails. RecyclerTabLayout extends RecyclerView, so tab views are created by an adapter and recycled as they scroll off screen, while the view draws a line indicator under the selected tab with the same animated behavior as TabLayout.

Animated demo of RecyclerTabLayout scrolling through tabs and moving the selection indicator
Figure 1. RecyclerTabLayout in action: the indicator follows the selected tab while tab views are recycled

Core concepts

  • Adapter-driven tabs: tabs are supplied through a regular RecyclerView.Adapter, view holder and item view.

  • Selection indicator: a line drawn under the selected tab, whose color, height and margins are configurable (indicatorColor, indicatorHeight, indicatorMarginLeft, indicatorMarginRight, or the tabIndicator* XML attributes).

  • Programmatic selection: setCurrentItem(position, smoothScroll) moves the selection and animates the indicator; setAutoSelectionMode(autoSelect) selects tabs automatically while scrolling.

flowchart LR A["RecyclerView.Adapter"] -->|"binds tab views"| R["RecyclerTabLayout"] C["setCurrentItem(position)"] --> R R -->|"draws"| I["Animated selection indicator"]

Next steps