code: @Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          try {
              int mode = MeasureSpec.getMode(heightMeasureSpec);
  
              if (mode == MeasureSpec.UNSPECIFIED || mode == MeasureSpec.AT_MOST) {
                  super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                  int height = 0;
                  for (int i = 0; i < getChildCount(); i++) {
                      View child = getChildAt(i);
                      if (child != null) {
                          child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
                          int h = child.getMeasuredHeight();
                          if (h > height) {
                              height = h;
                          }
                      }
                  }
                  heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
              }
  
              super.onMeasure(widthMeasureSpec, heightMeasureSpec);
          } catch (RuntimeException e) {
              Log.e(TAG, "Exception during WrapContentViewPager onMeasure " + e.toString());
          }
      }
docs: Allows to redraw the view size to wrap the content of the bigger child.
  
  @param widthMeasureSpec  with measured
  @param heightMeasureSpec height measured