title: Constraint Layout Width and Height in Java as Root Parent
body: <p>Here is my code and maybe because of some reason I cannot position my TextView and Button in the middle. What is wrong with my code?</p>
  
  <pre><code>ConstraintSet constraintSet = new ConstraintSet();
          int parentId = ConstraintSet.PARENT_ID;
  
      //parent
      ConstraintLayout orderProcessedLayout = new ConstraintLayout(getApplicationContext());
      int constraintId = orderProcessedLayout.getId();
  
      //Text View
      TextView thanksTextView = new TextView(this);
      int textViewId = thanksTextView.getId();
      orderProcessedLayout.addView(thanksTextView, 0);
  
      //ButtonView
      Button reOrderButton = new Button(this);
      int buttonViewId = reOrderButton.getId();
      orderProcessedLayout.addView(reOrderButton, 1);
  
      /*Setting Views Attributes*/
      //Layout View
      //setting constraints
      constraintSet.clone(orderProcessedLayout);  //cloning ConstraintSet
      ConstraintLayout.LayoutParams constraintParams = new ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.WRAP_CONTENT, ConstraintLayout.LayoutParams.WRAP_CONTENT);
      constraintParams.setMargins(16,16,16,16);
      orderProcessedLayout.setLayoutParams(constraintParams);
      //todo set the width and height to be match constraint
  
      //Text View
      CharSequence thanksText = "THANK YOU";
      thanksTextView.setText(thanksText);
      thanksTextView.setTextColor(Color.BLUE);
      thanksTextView.setHighlightColor(Color.BLACK);
  
      //setting constraints
      constraintSet.connect(textViewId, ConstraintSet.START, constraintId, ConstraintSet.START);
      constraintSet.connect(textViewId, ConstraintSet.END, constraintId, ConstraintSet.END);
      constraintSet.connect(textViewId, ConstraintSet.TOP, constraintId, ConstraintSet.TOP);
      constraintSet.connect(textViewId, ConstraintSet.BOTTOM, constraintId, ConstraintSet.BOTTOM);
  
      //Button View
      CharSequence reOrderText = "ORDER AGAIN";
      reOrderButton.setText(reOrderText);
  
      //Button Action
      reOrderButton.setClickable(true);
      reOrderButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              orderCancelled(null);
          }
      });
  
      //setting constraints
      constraintSet.connect(buttonViewId, ConstraintSet.START, constraintId, ConstraintSet.START);
      constraintSet.connect(buttonViewId, ConstraintSet.END, constraintId, ConstraintSet.END);
      constraintSet.connect(buttonViewId, ConstraintSet.BOTTOM, constraintId, ConstraintSet.BOTTOM);
      constraintSet.connect(buttonViewId, ConstraintSet.TOP, textViewId, ConstraintSet.BOTTOM);
  
      //applying everything
      constraintSet.applyTo(orderProcessedLayout);
  </code></pre>
  
  <p>And when I set width and height to MATCH_CONSTRAINT or MATCH_CONSTRAINT_SPREAD, my views just disappear from Screen.</p>
  
  <p>What have I done wrong here?</p>
  
  <p><a href="https://i.stack.imgur.com/dIQ0Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dIQ0Y.png" alt="When width and height are set to WRAP_CONTENT or MATCH_PARENT"></a></p>
  
  <p>Do you have a solution to correct the desgin so it looks like <a href="https://i.stack.imgur.com/LnZCq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LnZCq.png" alt="this"></a></p>