private void propagateScroll(int scrollY) { // Set scrollY for the fragments that are not created yet mPagerAdapter.setScrollY(scrollY); // Set scrollY for the active fragments for (int i = 0; i < mPagerAdapter.getCount(); i++) { // Skip current item if (i == mPager.getCurrentItem()) { continue; } // Skip destroyed or not created item FlexibleSpaceWithImageBaseFragment f = (FlexibleSpaceWithImageBaseFragment) mPagerAdapter.getItemAt(i); if (f == null) { continue; } View view = f.getView(); if (view == null) { continue; } f.setScrollY(scrollY, mFlexibleSpaceHeight); f.updateFlexibleSpace(scrollY); } }
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); } }