title: Views are gone when ConstraintSet.applyTo
body: <p>I'm trying to extend the ConstraintLayout functionality to have a ProgressBar with fullscreen translucent background color. The idea is that I could reuse this layout and call <code>hideLoading()</code> and <code>showLoading()</code>. Progress bar has to be centered.</p>
  
  <p><strong>Problem is</strong>: when <code>constraintSet.applyTo(this)</code> is called all views that had <code>ConstraintSet.connect(...)</code> on them are GONE, or not drawn. As all operations on them are ignored and they are not displayed on the screen at all.</p>
  
  <p>Here is what I have :</p>
  
  <pre><code>public class ConstraintLayout extends android.support.constraint.ConstraintLayout {
  
      private View background;
      private ProgressBar progressBar;
  
      public ConstraintLayout(Context context) {
          super(context);
          addLoader();
      }
  
      public ConstraintLayout(Context context, AttributeSet attrs) {
          super(context, attrs);
          addLoader();
      }
  
      public ConstraintLayout(Context context, AttributeSet attrs, int defStyleAttr) {
          super(context, attrs, defStyleAttr);
          addLoader();
      }
  
      private void addLoader(){
          int wrapContent = LayoutParams.WRAP_CONTENT;
          int matchParent = LayoutParams.MATCH_PARENT;
  
          ConstraintSet constraintSet = new ConstraintSet();
          constraintSet.clone(this);
  
          background = new View(getContext());
          background.setBackgroundColor(getResources()
                  .getColor(R.color.background_loader_color));
          background.setId(generateViewId());
          addView(background, new ConstraintLayout.LayoutParams(matchParent, matchParent));
  
          constraintSet.connect(background.getId(), ConstraintSet.TOP, 
                  ConstraintSet.PARENT_ID, ConstraintSet.TOP, 0);
          constraintSet.connect(background.getId(), ConstraintSet.BOTTOM, 
                  ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, 0);
          constraintSet.connect(background.getId(), ConstraintSet.LEFT, 
                  ConstraintSet.PARENT_ID, ConstraintSet.LEFT, 0);
          constraintSet.connect(background.getId(), ConstraintSet.RIGHT, 
                  ConstraintSet.PARENT_ID, ConstraintSet.RIGHT, 0);
  
          progressBar = new ProgressBar(getContext(), null, android.R.attr.progressBarStyleLarge);
          progressBar.setId(generateViewId());
          addView(progressBar, new ConstraintLayout.LayoutParams(wrapContent, wrapContent));
  
          constraintSet.connect(progressBar.getId(), ConstraintSet.TOP, 
                  ConstraintSet.PARENT_ID, ConstraintSet.TOP, 0);
          constraintSet.connect(progressBar.getId(), ConstraintSet.BOTTOM, 
                  ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM, 0);
          constraintSet.connect(progressBar.getId(), ConstraintSet.START, 
                  ConstraintSet.PARENT_ID, ConstraintSet.START, 0);
          constraintSet.connect(progressBar.getId(), ConstraintSet.END, 
                  ConstraintSet.PARENT_ID, ConstraintSet.END, 0);
  
          constraintSet.applyTo(this);
      }
  
      public void showLoading(){
          background.setVisibility(VISIBLE);
          progressBar.setVisibility(VISIBLE);
      }
  
      public void hideLoading(){
          background.setVisibility(GONE);
          progressBar.setVisibility(GONE);
      }
  }
  </code></pre>
  
  <p>Here is what I have
  <a href="https://i.stack.imgur.com/xk3lxm.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/xk3lxm.jpg" alt="img"></a>
  and what I want
  <a href="https://i.stack.imgur.com/gNG6Wm.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/gNG6Wm.jpg" alt="what i want"></a></p>