title: Android ViewPager with dynamic height
body: <p>I have a <code>ViewPager</code> to show some Fragments and swipe between them but the height of the <code>ViewPager</code> is dynamic based on the content.
  Assume I have multiple list that each list placed in one tab and by changing tabs the height of <code>ViewPager</code> should change properly
  I created a custom <code>ViewPager</code> and overrided <code>onMeasure</code> but the problem is <code>ViewPager</code> creates the next fragment sooner that current fragment (visible one) gets It's height from next fragment measure.</p>
  <p>Here is <code>MyViewPager</code> :</p>
  <pre><code>public class MyViewPager extends ViewPager {
  
      public MyViewPager(Context context) {
          super(context);
      }
      
      public MyViewPager(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
      
      @Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          int height = 0;
          for(int i = 0; i &lt; getChildCount(); i++) {
              View child = getChildAt(i);
              child.measure(
                  widthMeasureSpec,
                  MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
              );
              int h = child.getMeasuredHeight();
              if(h &gt; height) height = h;
          }
      
          heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
      
          super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      }
      
  }
  </code></pre>
  <p>I also tried to trigger <code>onMeasure</code> method of <code>MyViewPager</code> when the fragment become visible like below but nothing changes.</p>
  <pre><code>@Override
  public void setUserVisibleHint(boolean isVisibleToUser) {
      super.setUserVisibleHint(isVisibleToUser);
      if (isVisibleToUser) {
          PostDetailsActivity activity = (PostDetailsActivity) getActivity();
          activity.pagerParent.requestLayout();
          activity.pagerParent.invalidate();
      }
  }
  </code></pre>