Fragment方法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zsp_android_com/article/details/85280179

setUserVisibleHint

简介

Set a hint to the system about whether this fragment's UI is currently visible to the user. This hint defaults to true and is persistent across fragment instance state save and restore.
An app may set this to false to indicate that the fragment's UI is scrolled out of visibility or is otherwise not directly visible to the user. This may be used by the system to prioritize operations such as fragment lifecycle updates or loader ordering behavior.
Note: This method may be called outside of the fragment lifecycle. and thus has no ordering guarantees with regard to fragment lifecycle method calls.

源码

/**
* @param isVisibleToUser true if this fragment's UI is currently visible to the user (default), false if it is not.                      
*/
public void setUserVisibleHint(boolean isVisibleToUser) {
   if (!mUserVisibleHint && isVisibleToUser && mState < STARTED) {
       mFragmentManager.performPendingDeferredStart(this);
   }
   mUserVisibleHint = isVisibleToUser;
   mDeferStart = !isVisibleToUser;
}

/**
 * @return The current value of the user-visible hint on this fragment.
 * @see #setUserVisibleHint(boolean)
 */
public boolean getUserVisibleHint() {
    return mUserVisibleHint;
}

说明

Fragment用户可见调setUserVisibleHint()传true,fragment用户不可见setUserVisibleHint()则false。传统Fragment生命周期看不到该函数。setUserVisibleHint()于onCreateView()前执行。

猜你喜欢

转载自blog.csdn.net/zsp_android_com/article/details/85280179
今日推荐