//添加tab 并设置为已选中 tab_layout.addTab(tab_layout.newTab().setText("请选择"),0,true) //跳转到selectedPos位置,并让其置顶(只要有置顶的条件) (recycle_view.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(selectedPos,0)
监听tab的切换
tab_layout.addOnTabSelectedListener(object : TabLayout.BaseOnTabSelectedListener<TabLayout.Tab> { override fun onTabReselected(p0: TabLayout.Tab?) { } override fun onTabUnselected(p0: TabLayout.Tab?) { } override fun onTabSelected(p0: TabLayout.Tab?) { //p0?.position //这里重新加载recycleView的数据 } })