code: @Override
      protected void onLayout(boolean changed, int l, int t, int r, int b) {
          super.onLayout(changed, l, t, r, b);
  
          if(getOrientation() == HORIZONTAL) {
              int N = getChildCount();
              for (int i = 0; i < N; i++) {
  
                  View child = getChildAt(i);
                  int width = child.getWidth();
                  if (width > MAX_BUTTON_WIDTH || (N>=3 && width > MIN_BUTTON_WIDTH)) {
  
                      // Clear out the children list in preparation for new manipulation
                      children.clear();
  
                      // Update the children's params
                      for (int j = 0; j < N; j++) {
                          RippleView chd = (RippleView) getChildAt(j);
                          Button btn = (Button) chd.getChildAt(0);
                          btn.setGravity(Gravity.END|Gravity.CENTER_VERTICAL);
                          children.add(chd);
                      }
  
                      // Clear out the chitlens
                      removeAllViews();
  
                      // Sort buttons properly
                      Collections.sort(children, mButtonComparator);
  
                      // Re-Add all the views
                      for(int j=0; j<children.size(); j++){
                          View chd = children.get(j);
                          addView(chd);
                      }
  
                      // Switch orientation
                      setOrientation(VERTICAL);
                      requestLayout();
                      return;
                  }
  
  
              }
          }
  
  
      }
docs: if we detect that one of the dialog buttons are greater
  than the max horizontal layout width of 124dp then to switch the
  orientation to {@link #VERTICAL}