是Fragment.setUserVisibleHint()调用的Andr​​oid系统? [英] Is Fragment.setUserVisibleHint() called by the android System?

查看:209
本文介绍了是Fragment.setUserVisibleHint()调用的Andr​​oid系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

推荐答案

纵观<一href="https://android.googlesource.com/platform/frameworks/support/+/refs/heads/master/v4/java/android/support/v4/app/Fragment.java">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).

请注意虽然,<一个href="https://android.googlesource.com/platform/frameworks/support/+/refs/heads/master/v4/java/android/support/v4/app/FragmentPagerAdapter.java">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.

这篇关于是Fragment.setUserVisibleHint()调用的Andr​​oid系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆