title: ListView overlay another layout when scroll
body: <p>Actually I don't know how it properly called - overlay, parallax or slideUP, whatever, I have an Activity called "cafe details" which presents a Container(LinearLayout) with header information (name, min price, delivery time min e.t.c) and other container (ViewPager) which contains a ExpandableListView with something information (menus&amp;dishes) and all I want to do is slide up my Viewpager when scrolls listview to scpecific Y position to cover(or overlay) header information.</p>
  
  <p><img src="https://i.stack.imgur.com/QyEPl.png" alt="MyPic"></p>
  
  <p>A similar effect (but with parallax that I don't need to use) looks like this</p>
  
  <p><img src="https://i.stack.imgur.com/mf8vd.gif" alt="Similar effect"></p>
  
  <p>I can detect when user scrolling listview down or up but how I can move container with ViewPager to overlay other container? Please give me ideas, regards.</p>
  
  <p><strong>UPD</strong>
  I have tried a huge number of ways how to implement it and all of them unfortunately are not suitable. So now I have come to next variant - add scroll listener to ListView, calculate scrollY position of view and then based on that move the viewpager on y axis by calling setTranslationY(); 
  Here is some code</p>
  
  <p>1) ViewPager's fragment</p>
  
  <pre><code>    mListView.setOnScrollListener(new AbsListView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(AbsListView absListView, int i) {
  
          }
  
          @Override
          public void onScroll(AbsListView absListView, int i, int i1, int i2) {
              if (getActivity() != null) {
                  ((MainActivity) getActivity()).resizePagerContainer(absListView);
              }
          }
      });
  </code></pre>
  
  <p>2) MainActivity</p>
  
  <pre><code>//object fields
  
  int previousPos; 
  private float minTranslation;
  private float minHeight;
  
  &lt;--------somewhere in onCreate
  
  minTranslation = - (llVendorDescHeaders.getMeasuredHeight()+llVendorDescNote.getMeasuredHeight());
  //llVendorDescHeaders is linearLayout with headers that should be hidden
  //lVendorDescNote is a textView on green background;
  
  minHeight = llVendorDescriptionPagerContainer.getMeasuredHeight();
  //llVendorDescriptionPagerContainer is a container which contains ViewPager
  ---------&gt;
  
  public void resizePagerContainer(AbsListView absListView){
  
      final int scrollY = getScrollY(absListView);
      if (scrollY != previousPos) {
          final float translationY = Math.max(-scrollY, minTranslation);
  
          llVendorDescriptionPagerContainer.setTranslationY(translationY);
  
          previousPos = scrollY;
      }
  }
  
  private int getScrollY(AbsListView view) {
      View child = view.getChildAt(0);
      if (child == null) {
          return 0;
      }
  
      int firstVisiblePosition = view.getFirstVisiblePosition();
      int top = child.getTop();
  
      return -top + firstVisiblePosition * child.getHeight() ;
  }
  </code></pre>
  
  <p>This simple solution unfortunately has a problem - it is blinking and twitching (I don't know how to call it right) when scrolls slowly. So instead setTranslationY() I've used an objectAnimator:</p>
  
  <pre><code>public void resizePagerContainer(AbsListView absListView){
      .............
  
      ObjectAnimator moveAnim = ObjectAnimator.ofFloat(llVendorDescriptionPagerContainer, "translationY", translationY);
      moveAnim.start();
     ..............
  }
  </code></pre>
  
  <p>I don't like this solution because 1) anyway it does resize viewpager with delay, not instantly 2) I don't think that is good idea to create many ObjectAnimator's objects every time when I scroll my listView.
  Need your help and fresh ideas. Regards.</p>