How to scroll tablayout programmatically - Android

前端 未结 13 2357
终归单人心
终归单人心 2021-02-07 00:31

I have created 30 scrollable tabs using tablayout.

So first three tabs are visible on screen and rest of them are invisible which can be scroll using swipe gesture.

13条回答
  •  不要未来只要你来
    2021-02-07 01:00

    If your TabLayout is used in conjunction with a ViewPager, which is common, simply add the following in the onCreate() method in your Activity:

    tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager);
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout);
    

    That some of your tabs are not being shown indicates the tabMode attribute is set to app:tabMode="scrollable".

提交回复
热议问题