public void onScrollChanged ( int scrollY , Scrollable s ) { FlexibleSpaceWithImageBaseFragment fragment = ( FlexibleSpaceWithImageBaseFragment ) mPagerAdapter . getItemAt ( mPager . getCurrentItem ( ) ) ; if ( fragment == null ) { return ; } View view = fragment . getView ( ) ; if ( view == null ) { return ; } Scrollable scrollable = ( Scrollable ) view . findViewById ( R . id . scroll ) ; if ( scrollable == null ) { return ; } if ( scrollable == s ) { // This method is called by not only the current fragment but also other fragments // when their scrollY is changed. // So we need to check the caller(S) is the current fragment. int adjustedScrollY = Math . min ( scrollY , mFlexibleSpaceHeight - mTabHeight ) ; translateTab ( adjustedScrollY , false ) ; propagateScroll ( adjustedScrollY ) ; } }
Called by children Fragments when their scrollY are changed . They all call this method even when they are inactive but this Activity should listen only the active child so each Fragments will pass themselves for Activity to check if they are active .