是Fragment.setUserVisibleHint()调用的Andr​​oid系统?系统、setUserVisibleHint、Fragment、oid

由网友(才下了眉头)分享简介:是 Fragment.setUserVisibleHint()方法调用的系​​统,或我们手动调用呢?Is Fragment.setUserVisibleHint() method called by the System , ordo we call it manually ?推荐答案纵观sources,它看...

Fragment.setUserVisibleHint()方法调用的系​​统,或 我们手动调用呢?

Is Fragment.setUserVisibleHint() method called by the System , or do we call it manually ?

推荐答案

纵观sources,它看起来像这样的系统主要是用于把一个寻呼机片段。 您(或片段寻呼机,例如实施)应设置为提示(如片段源代码中的注释所提供的应用程序提示说的),这样它可以,例如,延迟其加载(初始化)如果不可见的,(用成一个寻呼机,当再次典型需要)优先的可见片段装载

Looking at the sources, it looks like this system is mostly intended for fragments put in a pager. You (or the implementation of the fragment pager for example) should set it as a hint ("Hint provided by the app" as a comment in the Fragment source says) so that it can, for example, defer its loading (initialization) if not visible and prioritize the loading of visible fragments (typical need when used into a pager, again).

请注意虽然,FragmentPagerAdapter利用了这一点,并适当地调用 setUserVisibleHint()其片段,这就是为什么我猜你看到一些人建议,以如覆盖 setUserVisibleHint()来知道什么时候一个片段得到用户可见的还是不(这将因此只能工作在片段是在 FragmentPagerAdapter ,不时还只是把例如通常活动布局)。

Note though, that the FragmentPagerAdapter makes use of this and properly calls setUserVisibleHint() on its fragments, which is why I guess you see some people advising to e.g. override setUserVisibleHint() to know when a fragment gets visible to the user or not (and this would thus only work when the fragment is inside a FragmentPagerAdapter, not when just put in a usual activity layout for example).

因此​​,要清楚地回答这个问题:你手动调用它, FragmentPagerAdapter 也可手动将其称为

So to answer the question clearly: you call it manually, and FragmentPagerAdapter also calls it manually.

阅读全文

相关推荐

最新文章