title: UI too slow to be inflated, causing application to be slow
body: <p>I have a constraint layout inside a ScrollView. This ConstraintLayout is supposed to be a parent for other Views that will be added into it, as shown:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;android.support.constraint.ConstraintLayout
      android:id="@+id/generated_main_constraint"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>When I try to add view to this ConstraintLayout, I inflate the view from XML, with the following code:</p>
  
  <pre><code>(ConstraintLayout) getLayoutInflater().inflate(R.layout.box_npcs, MAIN_CONSTRAINT, false);
  </code></pre>
  
  <p>This layout is defined in XML1 (end of the question).</p>
  
  <p>Then I add TextViews with information to this Layout's LinearLayout, for that I use a programatically created TextView and add it into the layout</p>
  
  <pre><code>linearLayout.addView(new TextView("Foo"));
  </code></pre>
  
  <p>With that setup, I add this box to the main constraint layout.</p>
  
  <p>The problem is: <strong>When I try to add more than 5 views, it takes a long time to proccess the UI</strong>, taking up to 5 seconds on the max amount of view to be added (50).</p>
  
  <p><strong>How can I add Complex Views to a ConstraintLayout in a way that it doesn't lag when trying to add the views?</strong></p>
  
  <p>XML1:</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"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/box_npcs"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"&gt;
  
  
  &lt;ImageView
      android:id="@+id/npcImage"
      android:layout_width="88dp"
      android:layout_height="88dp"
      android:layout_marginBottom="0dp"
      android:layout_marginLeft="8dp"
      android:layout_marginTop="8dp"
      android:scaleType="fitXY"
      app:layout_constraintBottom_toBottomOf="@+id/layoutInformation"
      app:layout_constraintLeft_toLeftOf="parent"
      app:layout_constraintTop_toTopOf="@+id/layoutInformation"
      app:srcCompat="@drawable/camera" /&gt;
  
  &lt;android.support.constraint.ConstraintLayout
      android:id="@+id/layoutInformation"
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_marginLeft="8dp"
      android:layout_marginRight="8dp"
      android:layout_marginTop="8dp"
      android:maxWidth="280dp"
      app:layout_constraintHorizontal_bias="0.0"
      app:layout_constraintLeft_toRightOf="@+id/npcImage"
      app:layout_constraintRight_toRightOf="parent"
      app:layout_constraintTop_toTopOf="parent"&gt;
  
      &lt;TextView
          android:id="@+id/top_priority"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_marginRight="0dp"
          android:layout_marginTop="0dp"
          android:ellipsize="start"
          android:text="DummyTextIsDummy"
          android:textAppearance="@style/TextAppearance.AppCompat.Body1"
          android:textColor="@color/common_google_signin_btn_text_light_default"
          android:textSize="22sp"
          android:textStyle="bold"
          android:typeface="normal"
          app:layout_constraintHorizontal_bias="0.0"
          app:layout_constraintLeft_toLeftOf="parent"
          app:layout_constraintRight_toRightOf="parent"
          app:layout_constraintTop_toTopOf="parent"
          tools:ignore="HardcodedText" /&gt;
  
      &lt;LinearLayout
          android:id="@+id/linearLayout_high_highest_normal"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:orientation="vertical"
          app:layout_constraintLeft_toLeftOf="@+id/top_priority"
          app:layout_constraintTop_toBottomOf="@+id/top_priority" /&gt;
  &lt;/android.support.constraint.ConstraintLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p>Images for examples:
  Each 'box' in this screen is a box in the Main Constraint Layout.
  Each TextLine is a different TextView added to the LinearLayout
  <a href="https://i.stack.imgur.com/1rm9b.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1rm9b.png" alt=""></a></p>