title: Android ParallaxHeaderViewPager in ScrollView not working
body: <p>I'm using <a href="https://github.com/kmshack/Android-ParallaxHeaderViewPager" rel="nofollow">Android-ParallaxHeaderViewPager</a> in my new project. It's working perfectly using a listview inside fragments, but it's not working when I use a scrollview (the header gets fixed and doesn't make the same effect as in a listview fragment). Any help would be appreciated.
  Here is my code:</p>
  
  <p><strong>fragment_lore.xml</strong> (Not working)</p>
  
  <pre><code>&lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/scrollViewLore"&gt;
          &lt;TextView
              android:id="@+id/championLore"
              android:layout_width="match_parent"
              android:layout_height="match_parent"/&gt;
  &lt;/ScrollView&gt;
  </code></pre>
  
  <p><strong>LoreFragment.java</strong></p>
  
  <pre><code>public class LoreFragment extends ScrollTabHolderFragment implements OnScrollListener {
  
      private int mPosition;
      private ScrollView mScrollView;
      private int mTabBarHeight;
      private int mTopImageHeight;
  
      public static final LoreFragment newInstance(Integer position, Integer pos){
          LoreFragment fragment = new LoreFragment();
          Bundle args = new Bundle();
          args.putInt("position",position);
          args.putInt("pos",pos);
          fragment.setArguments(args);
          return fragment;
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          mPosition = getArguments().getInt("position");
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_lore,container,false);
          mScrollView = (ScrollView) view.findViewById(R.id.scrollViewLore);
          mTabBarHeight = getResources().getDimensionPixelSize(R.dimen.tab_bar_height);
          KenBurnsView headerImg = (KenBurnsView) getActivity().findViewById(R.id.header_picture);
          mTopImageHeight = headerImg.getHeight();
          TextView loreView = (TextView) view.findViewById(R.id.championLore);
          Integer pos = Integer.valueOf(getArguments().getInt("pos"));
          String lore = Cache.champions.get(pos).getDescription();
          lore = lore.replace("&lt;br&gt;","\n");
          loreView.setText(lore);
          return view;
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
  
      }
  
      @Override
      public void adjustScroll(int scrollHeight) {
          if (scrollHeight == 0 &amp;&amp; mScrollView.getScrollY() &gt; mTopImageHeight - mTabBarHeight) {
              // ScrollView does not need to adjust scroll, as the tab bar is its sticky position
              return;
          }
          mScrollView.scrollTo(mScrollView.getScrollX(), -scrollHeight + mTopImageHeight - mTabBarHeight);
      }
  
      @Override
      public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
          if (mScrollTabHolder != null)
              mScrollTabHolder.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount, mPosition);
      }
  
      @Override
      public void onScrollStateChanged(AbsListView view, int scrollState) {
          // nothing
      }
  }
  </code></pre>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class ChampionDetailsActivity extends ActionBarActivity implements ScrollTabHolder, ViewPager.OnPageChangeListener{
  ...
  @Override
      public void onPageScrollStateChanged(int arg0) {
          // nothing
      }
  
      @Override
      public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
          // nothing
      }
  
      @Override
      public void onPageSelected(int position) {
          SparseArrayCompat&lt;ScrollTabHolder&gt; scrollTabHolders = mPagerAdapter.getScrollTabHolders();
          ScrollTabHolder currentHolder = scrollTabHolders.valueAt(position);
  
          currentHolder.adjustScroll((int) (mHeader.getHeight() + mHeader.getTranslationY()));
      }
  
      @Override
      public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount, int pagePosition) {
          if (mViewPager.getCurrentItem() == pagePosition) {
              int scrollY = getScrollY(view);
              mHeader.setTranslationY(Math.max(-scrollY, mMinHeaderTranslation));
              float ratio = clamp(mHeader.getTranslationY() / mMinHeaderTranslation, 0.0f, 1.0f);
              setTitleAlpha(clamp(5.0F * ratio - 4.0F, 0.0F, 1.0F));
          }
      }
  
      @Override
      public void adjustScroll(int scrollHeight) {
          // nothing
      }
  
      public int getScrollY(AbsListView view) {
          View c = view.getChildAt(0);
          if (c == null) {
              return 0;
          }
  
          int firstVisiblePosition = view.getFirstVisiblePosition();
          int top = c.getTop();
  
          int headerHeight = 0;
          if (firstVisiblePosition &gt;= 1) {
              headerHeight = mHeaderHeight;
          }
  
          return -top + firstVisiblePosition * c.getHeight() + headerHeight;
      }
  
      public static float clamp(float value, float max, float min) {
          return Math.max(Math.min(value, min), max);
      }
  
  public int getActionBarHeight() {
          if (mActionBarHeight != 0) {
              return mActionBarHeight;
          }
          getTheme().resolveAttribute(android.R.attr.actionBarSize, mTypedValue, true);
          mActionBarHeight = TypedValue.complexToDimensionPixelSize(mTypedValue.data, getResources().getDisplayMetrics());
          return mActionBarHeight;
      }
  ...
  public class PagerAdapter extends FragmentPagerAdapter {
  
          private Integer pos;
          private ScrollTabHolder mListener;
          private SparseArrayCompat&lt;ScrollTabHolder&gt; mScrollTabHolders;
          ...
  
          public PagerAdapter(FragmentManager fm) {
              super(fm);
              mScrollTabHolders = new SparseArrayCompat&lt;ScrollTabHolder&gt;();
          }
  
          public PagerAdapter(FragmentManager fm, Integer pos) {
              super(fm);
              this.pos=pos;
              mScrollTabHolders = new SparseArrayCompat&lt;ScrollTabHolder&gt;();
  
          }
  
          public void setTabHolderScrollingContent(ScrollTabHolder listener) {
              mListener = listener;
          }
  
  ...
  
          @Override
          public Fragment getItem(int position) {
  
              ScrollTabHolderFragment fragment = null;
              switch (position) {
                  case 0:
                      fragment = (ScrollTabHolderFragment) ListViewFragment.newInstance(position,pos);
                      break;
                  case 1:
                      fragment = (ScrollTabHolderFragment) LoreFragment.newInstance(position,pos);
                      break;
              }
  
              mScrollTabHolders.put(position, fragment);
              if (mListener != null) {
                  fragment.setScrollTabHolder(mListener);
              }
  
              return fragment;
          }
  
          public SparseArrayCompat&lt;ScrollTabHolder&gt; getScrollTabHolders() {
              return mScrollTabHolders;
          }
  </code></pre>
  
  <p>Also, I tried <a href="http://nerds.airbnb.com/host-experience-android/" rel="nofollow">that article</a> but I couldn't fix my scrollview. Let me know if you need more pieces of my code.</p>
  
  <p>Thanks in advance.</p>