private void layoutWithHeightDetection() {
    ListView view = (ListView) mView;
    mHeightMeasureSpec = makeMeasureSpec(HEIGHT_LIMIT, MeasureSpec.EXACTLY);
    layoutInternal();

    if (view.getCount() != view.getChildCount()) {
      throw new IllegalStateException("the ListView is too big to be auto measured");
    }

    int bottom = 0;

    if (view.getCount() > 0) {
      bottom = view.getChildAt(view.getCount() - 1).getBottom();
    }

    if (bottom == 0) {
      bottom = 1;
    }

    mHeightMeasureSpec = makeMeasureSpec(bottom, MeasureSpec.EXACTLY);
    layoutInternal();
  }
Measure and layout the view after all the configuration is done.

@returns an AfterLayout object that can be used to perform common operations after the layout
    is done such as dispatchPreDraw()l.
core/src/main/java/com/facebook/testing/screenshot/ViewHelpers.java