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);
    }
  }
Пример #2
0
 private View prepareMenuView(View view, Bundle savedInstanceState) {
   mNavigationAdapter = new NavigationAdapter();
   mNavigationAdapter.add(MainFragment.class, R.string.demo);
   mNavigationAdapter.add(SettingsFragment.class, R.string.settings);
   mNavigationAdapter.add(OtherFragment.class, R.string.other);
   mNavigationAdapter.add(AboutFragment.class, R.string.about);
   mNavigationAdapter.onItemSelected(mCurrentPage, mFirstRun);
   ListView list = (ListView) view.findViewById(R.id.list);
   list.setAdapter(mNavigationAdapter);
   list.setOnItemClickListener(mNavigationAdapter);
   return view;
 }
 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);
   }
 }