1

I'm learning about tab layout because I need to use tab layout.

When i search for tab layout on Google, the one that comes up together is the view pager.

By the way, I'm not sure about the difference between tablayout and viewpager.

The tab layout has a menu at the top and screen switching is possible.

Although the view pager does not have tabs, it is possible to slide the screen just like the tab layout.

But why use the two together?

What's different?

Isn't it possible to slide in tab layout as well?

ybybyb
  • 1,385
  • 1
  • 12
  • 33
  • 3
    " it is possible to slide the screen just like the tab layout." -- no. `TabLayout` has no "screen". `TabLayout` is just the tabs, nothing more. – CommonsWare Jun 25 '21 at 17:41

1 Answers1

2

Yes, you can use TabLayout without viewPager. But without viewpager you won't be able to slide your page. You have to handle tabselect listener manually using this method then you have to click on the tab to navigate.

addOnTabSelectedListener(OnTabSelectedListener)

Likewise, you can use only Viewpager then you will be able to slide or swipe your page without any tabs.

From official doc

TabLayout

TabLayout provides a horizontal layout to display tabs.

Viewpager

Layout manager that allows the user to flip left and right through pages of data.

So Tablayout and viewpager are two different things but you can have the privilege of both tabs and slide only by combining them.

You can check here for tablaout without viewPager

TabLayout without using ViewPager

Rafiul
  • 1,560
  • 7
  • 19