ViewPager2
在没推出androidx之前,android生态有些混乱,自从Google官方开始重视这一问题以后 就有了后续的jetpack和一系列的控件
viewpager 我们一般是exends PageAdapter或者其他的适配器,完成不通类型之间页面滑动 A—>B---->C 默认会缓存2个页面的数据,有个缓存设计,也就是当前在B页面—C页面的数据会初始化,所以才有了懒加载(Fragment)
懒加载原理请移步---------> https://blog.csdn.net/qq_29769851/article/details/90712756
先看看ViewPager2的源码:
继承自ViewGroup
setAdapter
/**
-
Set a new adapter to provide page views on demand.
-
If you're planning to use {@link androidx.fragment.app.Fragment Fragments} as pages,
-
implement {@link androidx.viewpager2.adapter.FragmentStateAdapter FragmentStateAdapter}. If
-
your pages are Views, implement {@link RecyclerView.Adapter} as usual.
-
If your pages contain LayoutTransitions, then those LayoutTransitions must have
-
{@code animateParentHierarchy} set to {@code false}. Note that if you have a ViewGroup with
-
{@code animateLayoutChanges=“true”} in your layout xml file, a LayoutTransition is