我对所有标签使用相同的片段。
但是问题是片段的回收器视图的滚动仅适用于最后一个标签。
在“回收站”视图中,上一个选项卡不滚动。 下面是我的FragmentPagerAdapter代码:
class DataViewPagerAdapter(fm: FragmentManager?) : FragmentStatePagerAdapter(fm) {
var fragmentList: MutableList<Fragment> = ArrayList()
var fragmentTitleList: MutableList<String> = ArrayList()
override fun getItem(position: Int): Fragment {
return DataFragment.newInstance(position)
}
override fun getCount(): Int {
return 3
}
override fun getPageTitle(position: Int): CharSequence? {
return "Deepak"
}
}
这是我绑定适配器的代码:
var adapter = DataViewPagerAdapter( getChildFragmentManager())
dataViewpager.adapter = adapter
dataViewpager.offscreenPageLimit=1
tabLayout.setupWithViewPager(dataViewpager)
这是我的片段代码:
class DataFragment : Fragment() {
lateinit var recyclerView: RecyclerView
companion object {
fun newInstance(position: Int): DataFragment {
val fragment = DataFragment()
val args = Bundle()
args.putInt("KEY_POSITION", position)
args.putInt("KEY_ID",1)
fragment.setArguments(args)
return fragment
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
var view = LayoutInflater.from(activity).inflate(R.layout.fragment_data, null)
recyclerView = view.findViewById<RecyclerView>(R.id.recyclerView)
var adapter = DataFragmentAdapter()
recyclerView.layoutManager = GridLayoutManager(activity, 3)
recyclerView.adapter = adapter
return view;
}
}
答案 0 :(得分:0)
我不确定是否与您的问题有关,但是offscreenPageLimit
应该是您的适配器数量的大小。