How to test if a fragment view is visible to the user?

前端 未结 10 494
闹比i
闹比i 2020-11-28 04:42

I have a ViewPager, each page is a Fragment view. I want to test if a fragment is in a visible region. the Fragment.isVisible only test

  • the fragment is attache
10条回答
  •  离开以前
    2020-11-28 05:02

    I'm using "setMenuVisibility"-Method for resolving this Problem. As every Fragment can have actionbar-items this is the part where you can determine which Fragment is currently visible to the user.

    @Override
    public void setMenuVisibility(final boolean visible) {
        super.setMenuVisibility(visible);
        if (!visible) {
            //not visible anymore
        }else{
            yay visible to the user
        }
    }
    

提交回复
热议问题