code: private void registerScrollLayoutListener() {
          if (scrollView != null) {
              scrollView.getViewTreeObserver()
                      .addOnGlobalLayoutListener(createScrollViewLayoutListener(scrollView));
          } else if (listView != null) {
              listView.getViewTreeObserver()
                      .addOnGlobalLayoutListener(createScrollViewLayoutListener(listView));
          }
      }
docs: Registers an {@link OnGlobalLayoutListener} at the dialog's scroll view or list view, if
  present, in order to be able to adjust the initial visibilities of the dividers as soon as
  the respective view has been layouted.