title: Android ConstraintLayout: How to add a dynamic view one below another
body: <p>I am trying to add TextViews one below another at runtime in a Constraint Layout. But I always end up with just one textview and the rest hiding behind it. I tried several things including chaining the view, but nothing seems to work.</p>
  
  <pre><code>private void method(int position)
      {
          ConstraintSet set = new ConstraintSet();
          TextView textView = new TextView(getContext());
          int textViewId = 100 + position;
          //previousTextViewId = textViewId;
          textView.setId(textViewId);
          ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(0, WRAP_CONTENT);
          layoutParams.rightToRight = PARENT_ID;
          layoutParams.leftToLeft = guideline_60.getId(); //Vertical GuideLine of 60%
          layoutParams.rightMargin = 8;
          textView.setLayoutParams(layoutParams);
          if (Build.VERSION.SDK_INT &lt; 23)
          {
              textView.setTextAppearance(getContext(), R.style.textStyle);
          }
          else
          {
              textView.setTextAppearance(R.style.textStyle);
          }
          textView.setBackgroundColor(backgroundColor);
          textView.setText(categoryName);
          textView.setGravity(Gravity.CENTER);
  //markerLayout is the ConstraintLayout 
          markerLayout.addView(textView, position);
          set.clone(markerLayout);
          //set.addToVerticalChain(textView.getId(),previousTextViewId,PARENT_ID);
          set.connect(textView.getId(), ConstraintSet.TOP, markerLayout.getId(), ConstraintSet.TOP, 60);
          set.applyTo(markerLayout);
      }
  </code></pre>
  
  <p>I am expecting see something like this -</p>
  
  <p><a href="https://i.stack.imgur.com/t7c7v.png" rel="noreferrer"><img src="https://i.stack.imgur.com/t7c7v.png" alt="enter image description here"></a></p>