title: How to add left and right margins in constraint layout programatically
body: <p>I have created an image view programmatically, and added it to constraint layout. Now i want to add margins from left and right of the <code>imageView.</code></p>
  
  <p>This is what i did. </p>
  
  <pre><code>ImageView imageView = new ImageView(this);
  imageView.setId(View.generateViewId());
  constraintLayout.addView(imageView);
  
  //Convert DP to PX
  int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 
                                               10,
                                               getResources().getDisplayMetrics());
  
  //Loading image from URL by using Picasso.        
  Picasso.with(getApplicationContext())
         .load(imageURL)
         .placeholder(R.drawable.card_loading)
         .fit()
         .centerCrop()
         .into(imageView);
  
  imageView.setAdjustViewBounds(true);
  
  //Created Constraint Set.
  ConstraintSet set = new ConstraintSet();
  set.clone(constraintLayout);      
  set.constrainWidth(imageView.getId(), ConstraintSet.MATCH_CONSTRAINT);
  
  set.connect(imageView.getId(), ConstraintSet.TOP, eventsViewPager.getId(), ConstraintSet.BOTTOM, margin);
  
  set.connect(imageView.getId(), ConstraintSet.LEFT, ConstraintSet.PARENT_ID, ConstraintSet.LEFT, margin);
  
  set.connect(imageView.getId(), ConstraintSet.RIGHT, ConstraintSet.PARENT_ID, ConstraintSet.RIGHT, margin); 
  </code></pre>
  
  <p>Now the issue is that it creates margin from top, but no margin is added from left and right.</p>