title: Dynamically set the view width using constraint layout
body: <p>I am new to ConstraintLayout, Below is my xml file in this I am trying to achieve my Textview width dynamically. If my @+id/btn1 visibility is gone then TextView (@+id/tv1) should expand to full width. Please suggest what approach I should use to solve this problem with in the same way.</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:app="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_margin="@dimen/default_gap"
      app:layout_anchorGravity="right"&gt;
  
  
      &lt;TextView
          android:id="@+id/tv1"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:text="First thing first, if you have a min SDK lower than 17, you can now shift to using only start and end attribute and don’t repeat yourself for right and left"
          app:layout_constraintEnd_toEndOf="@+id/guideline_center"
          app:layout_constraintStart_toStartOf="parent" /&gt;
  
      &lt;Button
          android:id="@+id/tv_cur_type"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="RS"
          app:layout_constraintTop_toBottomOf="@+id/tv1" /&gt;
  
      &lt;android.support.constraint.Guideline
          android:id="@+id/guideline_center"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          app:layout_constraintGuide_percent="0.5" /&gt;
  
  
      &lt;Button
          android:id="@+id/btn1"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:visibility="visible"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toEndOf="@+id/guideline_center" /&gt;
  
      &lt;TextView
          android:id="@+id/tv2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Payment Mode"
          app:layout_constraintEnd_toEndOf="parent"
          app:layout_constraintStart_toEndOf="@+id/guideline_center"
          app:layout_constraintTop_toBottomOf="@+id/btn1" /&gt;
  
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p>Below is the screenshot,<a href="https://i.stack.imgur.com/9FE9J.png" rel="nofollow noreferrer">enter image description here</a> how it's looks now</p>
  
  <p>Required UI<a href="https://i.stack.imgur.com/XxoSs.png" rel="nofollow noreferrer">enter image description here</a></p>