title: How to programmatically add views and constraints to a ConstraintLayout?
body: <p>I'm having a problem to programmatically add views to a <code>ConstraintLayout</code>, and set up all the constraints required for the layout to work.  </p>
  
  <p>What I have at the moment doesn't work:</p>
  
  <pre><code>ConstraintLayout layout = (ConstraintLayout) findViewById(R.id.mainConstraint);
  ConstraintSet set = new ConstraintSet();
  set.clone(layout);
  
  ImageView view = new ImageView(this);
  layout.addView(view,0);
  set.connect(view.getId(), ConstraintSet.TOP, layout.getId(), ConstraintSet.TOP, 60);
  set.applyTo(layout);
  </code></pre>
  
  <p>The <code>ImageView</code> doesn't even appear on the layout. When adding to a <code>RelativeLayout</code>, it works like a charm.</p>
  
  <p>What can I do to create the constraints I need, so that my layout work again?</p>