title: How to make the height of ViewPager inside ScrollView to be MATCH_PARENT?
body: <p>Previously I had a problem showing <code>Fragment</code> from <code>ViewPager</code> inside a <code>ScrollView</code>. The problem was because we need to put the exact height for <code>ViewPager</code>. We cannot rely on <code>WRAP_CONTENT</code> or <code>MATCH_PARENT</code>. I solved it with code from <a href="https://github.com/vabhishek/WrapContentViewPagerDemo/blob/master/DynamicViewPager-master/app/src/main/java/com/example/vihaan/dynamicviewpager/CustomPager.java" rel="nofollow noreferrer">here</a>. Now, my problem is if the height of a <code>Fragment</code> is not full screen, I cannot slide the <code>ViewPager</code> with the empty part of my screen. I only can slide with the visible part of my <code>Fragment</code>. The following is the code.</p>
  
  <pre><code>public class CustomPager extends ViewPager {
  
      private View mCurrentView;
  
      public CustomPager(Context context) {
          super(context);
      }
  
      public CustomPager(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      @Override
      public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          if (mCurrentView == null) {
              super.onMeasure(widthMeasureSpec, heightMeasureSpec);
              return;
          }
          int height = 0;
          mCurrentView.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
          int h = mCurrentView.getMeasuredHeight();
          if (h &gt; height) height = h;
  
          //TODO: if (height &lt; empty space height of a screen) height = empty space height of a screen
  
          heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
  
          super.onMeasure(widthMeasureSpec, heightMeasureSpec);
      }
  
      public void measureCurrentView(View currentView) {
          mCurrentView = currentView;
          requestLayout();
      }
  
      public int measureFragment(View view) {
          if (view == null)
              return 0;
  
          view.measure(0, 0);
          return view.getMeasuredHeight();
      }
  }
  </code></pre>
  
  <p><strong>layout.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/scroll_view"
      android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:orientation="vertical"&gt;
  
          &lt;TextView
              android:id="@+id/text1"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" /&gt;
  
          &lt;TextView
              android:id="@+id/text2"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" /&gt;
  
          &lt;TextView
              android:id="@+id/text3"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" /&gt;
  
          &lt;com.example.CustomPager
              android:id="@+id/custom_pager"
              android:layout_width="match_parent"
              android:layout_height="match_parent" /&gt;
      &lt;/LinearLayout&gt;
  &lt;/ScrollView&gt;
  </code></pre>