isVisible
: 是關聯(lián)與fragment
生命周期的可見性的判斷
User Visible Hint
: 當fragment
的可見性與其生命周期沒有關系的時候,來進行對于可見性的判斷
在使用viewPager
進行添加若干fragment
的時候螺戳,當parentActivity
進行onStart()
的時候,里面所有的fragment
都會進行onStart()
,即只要在Parent
的可見狀態(tài)之中涎才,內部的所有的fragment
的isVisible()
都是true标沪,所以在viewPager
的時候,是根據(jù)當前的fragment是否被選中去判斷其的顯示與隱藏掘托,而當前這個fragment
是否被選中的標志在ViewPager
中就是UserVisibleHint
的值。
isVisible()
是使用FragmentManager
進行管理籍嘹,是對于當前fragment
是否對用戶“可見”的判定方式闪盔。這里的“可見”是指在onStart()
和onStop()
之間。
調用FragmentManager.beginTransaction().add/remove/replace()
等相關方法辱士,會導致Fragment
被添加和移除泪掀,從而改變isVisible()
的返回值
setUserVisibleHint(boolean isVisibleToUser)
是當使用viewPager
去管理若干fragment
的時候進行對于某fragment
在顯示跟隱藏的時候回調的方法
setUserVisibleHint()
從名字來看是給使用Fragment
的模塊來調用的,app也可以調用這個方法颂碘。
void setUserVisibleHint (boolean isVisibleToUser)
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.