FragmentStatePagerAdapter构造方法中,新增了个参数behavior的理解

AndroidStudio里的解释是这样子的:

androidx.fragment.app.FragmentStatePagerAdapter public FragmentStatePagerAdapter(@NonNull androidx.fragment.app.FragmentManager fm,  int behavior)

Constructor for FragmentStatePagerAdapter. If BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT is passed in, then only the current Fragment is in the Lifecycle.State.RESUMED state, while all other fragments are capped at Lifecycle.State.STARTED. If BEHAVIOR_SET_USER_VISIBLE_HINT is passed, all fragments are in the Lifecycle.State.RESUMED state and there will be callbacks to Fragment.setUserVisibleHint(boolean).

Params:
fm – fragment manager that will interact with this adapter
behavior – determines if only current fragments are in a resumed state

之前了解到Fragment的好处是只会加载当前页面的前后一页,节约了资源
现在看来,又有了优化哈,上面这段的大致意思应该是,如果int behavior设置为BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT ,则只加载当前这一张到某个状态中,叫做懒加载?如果设置为BEHAVIOR_SET_USER_VISIBLE_HINT ,就全部加载进去~

哎,也不知道是不是这样,好像没啥哈

猜你喜欢

转载自blog.csdn.net/qq_41446977/article/details/112846129